How to cast List<object> to List

前端 未结 3 550
醉酒成梦
醉酒成梦 2020-12-04 23:22

How can i cast a List to List?

(where SomethingElse is known to descend from obje

3条回答
  •  心在旅途
    2020-12-04 23:42

    I think you're close with the Cast expression. The difference is that Cast returns an IEnumerable, not a List.

    Try this:

    IEnumerable second = first.Cast();
    

    You can get a list by doing something similar:

    List second = first.Cast().ToList();
    

提交回复
热议问题