In C#, is it possible to cast a List to List?

前端 未结 5 1943
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-28 05:29

I want to do something like this:

List childList = new List();
...
List parentList = childList;

How

5条回答
  •  春和景丽
    2020-11-28 05:55

    Using LINQ:

    List parentList = childList.Cast().ToList();
    

    Documentation for Cast<>()

提交回复
热议问题