c# - How to get list of specific child instances from list of parent instances? -
the answer simple not find myself.
my classes follows
public class element { } public class lineelement : element { } public class circleelement : element { }
in code want achieve this:
list<element> elements = new list<element>(); list<lineelement> lines = elements.where( x=> ..........).tolist();
what way achieve without defining type specifying property (like string type
) in child classes?
you need oftype() method.
list<lineelement> lines = elements.oftype<lineelement>.tolist();
Comments
Post a Comment