C#
struct plane {
public int first;
public int second = 5;
public plane() { //has to be public
//first = 99; error, all uninitialized instance fields must be initialized
}
plane(int h) { //can be private
//first = 88; error, all uninitialized instance fields must be initialized
}
}
I am trying to understand the whole concept of struct initialization:
I am sorry but I need to ask 2 questions because I think they are very dependent on eacg other:
Why does the parameterless constructor have to be public? I assume It is because the implicit constructor is public but this reason is just not enough to explain it.
why do we HAVE to initialize all the non-static uninitialized fields? I mean we could do it later manually.

Erik Movsesyan59 reputationPosted Aug 7, 2022, 5:10 PM EDT
Vishal JoshiRank #377 · 6.7K reputationPosted Aug 8, 2022, 1:16 AM EDT
Vishal JoshiRank #377 · 6.7K reputationPosted Aug 7, 2022, 4:11 PM EDT