Duplicate:
Why Must I Initialize All Fields in my C# struct with a Non-Default Constructor?
If in the constructor of an struct like
internal struct BimonthlyPair
{
internal int year;
internal int month;
internal int count;
internal BimonthlyPair(int year, int month)
{
this.year = year;
this.month = month;
}
}
I don't initialize a field (count in this case) I get an error:
Field 'count' must be fully assigned before control is returned to the caller
But if I assign all fields, including count in this case, with something like
this.year = year;
this.month = month;
this.count = 0;
the error disappeared.
I think this happens because C# doesn't initialize struct fields when somebody creates a new struct object. But, why? As far as I know, it initialize variables in some other contexts, so why an struct is a different scenery?