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

前端 未结 14 1655
别跟我提以往
别跟我提以往 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:23

    I have a:

    private List Leerlingen = new List();
    

    And I was going to fill it with data collected in an List What finally worked for me was this one:

    Leerlingen = (List)_DeserialiseerLeerlingen._TeSerialiserenObjecten.Cast();
    

    .Cast it to the type you want to get an IEnumerable from that type, then typecast the IEnemuerable to the List<> you want.

    提交回复
    热议问题