How do I cast a List effectively?

前端 未结 8 1393
暖寄归人
暖寄归人 2020-12-08 15:09

I have a

List 

but I need a

List  

Is there a way to cast this in c

8条回答
  •  自闭症患者
    2020-12-08 15:50

    Since the list is coming from

    List list = (from i .... select i).ToList();
    

    Couldn't you just fix the "select i" part to instead return IDataField instead? Something like this:

    List list = (from i .... select (IDataField)i).ToList();
    

    If that doesn't work, perhaps the "Cast" extension to IEnumerable will work:

    List list2 = list.Cast();
    

提交回复
热议问题