Assume that we have the following struct
definition that uses generics:
public struct Foo<T>
{
public T First;
public T Second;
public Foo(T first)
{
this.First = first;
}
}
The compiler says
'Foo.Second' must be fully assigned before control is returned to the caller
However, if Foo
is a class, then it compiles successfully.
public class Foo<T>
{
public T First;
public T Second;
public Foo(T first)
{
this.First = first;
}
}
Why? Why the compiler treats them differently? Moreover if no constructor is defined in the first Foo
then it compiles. Why this behaviour?