Generics used in struct vs class

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

    The other answers explain the behaviour correctly, but neglect to mention the second part of your question, so here it is for completion.

    When you don't explicitly define a constructor, the compiler will produce a default constructor which assigns default values (e.g. null for objects, 0 for numbers etc.) to every field.

提交回复
热议问题