Suppose 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; } }
Compiler says
'Foo.Second' must be fully assigned before control is returned to the caller
However, if Foo is a class, it compiles successfully.
public class Foo<T> { public T First; public T Second; public Foo(T first) { this.First = first; } }
Why? Why does the compiler treat them differently? Moreover, if the constructor is not defined in the first Foo , then it compiles. Why is this behavior?
Sleiman jneidi
source share