0

What is the cause of the error on the screen?

public struct YetkiYapisiListesi { public bool STOKGUNCELLE =false ; public bool STOKSIL=false; public bool STOKLISTELE=false; } 

Non-static struct member cannot have initializer

0

2 Answers 2

1

C# does not allow structs to have initializers, the reason why has been debated before, see here: ( Why can't I initialize my fields in my structs? )

Simply remove the = false part from your field declarations.

Note that Boolean fields are false by default, making your assignment completely unnecessary.

If you absolutely need fields to have initialized to non-default values then you can still define an additional constructor that sets those values, however it cannot be the default (parameterless) constructor. One alternative option then, is to use a static factory method.

Sign up to request clarification or add additional context in comments.

Comments

1

You can't initialize field on Struct.

You will get the same result even if you ommit initializing :

public bool STOKGUNCELLE; public bool STOKSIL; public bool STOKLISTELE; public bool STOKHAREKET; 

Because bool default value are false .

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.