I have an interface defined as
public interface IReaderInfo
{
string Displayname {get;}
}
and a class that implements that interface
public class ReaderInfo : IReaderInfo
{
string DisplayName {get;}
}
I then created a function which return List
public List<ReaderInfo> GetReaders
{
var readers = new List<ReaderInfo>();
var Ireaders = someobject.Getreaders();// Returns the list of IReaderInfo.
// Now i would like cast Ireaders as readers and return.
}
How do i cast it?
You have to create a new list with casted items:
var readers = Ireaders.Cast<ReaderInfo>().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<ReaderInfo>().ToList();
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments