Why can't I pass List as a parameter to a method that accepts List<object>?

前端 未结 8 577
北恋
北恋 2021-01-11 13:31

The following code gives me this error:

Cannot convert from \'System.Collections.Generic.List\' to \'System.Collections.Generic.List\'.

8条回答
  •  遥遥无期
    2021-01-11 13:56

    C# (at present) does not support variance for generic types.

    However, if you're using C# 3.0, you can do this:

    FillSmartGrid( customers.Cast() );
    
        

    提交回复
    热议问题