Generics used in struct vs class

前端 未结 4 2075
半阙折子戏
半阙折子戏 2021-02-13 12:10

Assume that we have the following struct definition that uses generics:

public struct Foo
{
    public T First; 
    public T Second;

             


        
4条回答
  •  长情又很酷
    2021-02-13 12:28

    That's a requirement of structs in general -- it has nothing to do with generics. Your constructor must assign a value to all fields.

    Note the same error happens here:

    struct Foo
    {
        public int A;
        public int B;
    
        public Foo()
        {
            A = 1;
        }
    }
    

提交回复
热议问题