Generics used in struct vs class

前端 未结 4 2076
半阙折子戏
半阙折子戏 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:43

    Because it is a rule in C# that all fields must be assigned for structs (inline or in constructor). This is because of a struct nature. It has nothing about generic it or not generic.

提交回复
热议问题