Why can't I initialize my fields in my structs?

前端 未结 4 1937
天命终不由人
天命终不由人 2020-12-21 02:40

I am surprised that I can\'t initialize my fields in structs, why is it like that? Like:

struct MyStruct
{
    private int a = 90;
}

but it

4条回答
  •  Happy的楠姐
    2020-12-21 03:25

    In C#, a struct cannot declare a default constructor.

    The compiler moves the initialization statements to the constructor, which can't happen with a struct in C#.

提交回复
热议问题