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

John Saunders
  • 160,644
  • 26
  • 247
  • 397

2 Answers2

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.

Community
  • 1
  • 1
Dai
  • 141,631
  • 28
  • 261
  • 374
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 .

Perfect28
  • 11,089
  • 3
  • 25
  • 45