What is the syntax for a default constructor for a generic class?

后端 未结 3 1491
北荒
北荒 2020-12-13 01:36

Is it forbidden in C# to implement a default constructor for a generic class?

If not, why the code below does not compile? (When I remove it c

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-13 01:54

    And if you need the Type as a property:

    public class Cell
    {
        public Cell()
        {
            TheType = typeof(T);
        }
    
        public Type TheType { get;}
    }
    

提交回复
热议问题