In C#, why can't a List object be stored in a List<object> variable

前端 未结 14 1408
别跟我提以往
别跟我提以往 2020-11-22 03:42

It seems that a List object cannot be stored in a List variable in C#, and can\'t even be explicitly cast that way.

List sl = new List

        
14条回答
  •  别那么骄傲
    2020-11-22 04:30

    Mike - I believe contravariance isn't allowed in C# either

    See Generic type parameter variance in the CLR for some more info.

提交回复
热议问题