How do i convert a List to List in c#

后端 未结 4 1873
清酒与你
清酒与你 2020-12-18 07:38

I have an interface defined as

public interface IReaderInfo
{
    string Displayname {get;}
}

and a class that implements that interface

4条回答
  •  无人及你
    2020-12-18 07:48

    You have to create a new list with casted items:

    var readers = Ireaders.Cast().ToList();
    

    Or, if there is a possibility to have incompatible IReaderInfo entries and you only want the actual ReaderInfo objects in the result:

    var readers = Ireaders.OfType().ToList();
    

提交回复
热议问题