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's a complie time error. I don't know why it's a problem? Please explain this to me.
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#.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With