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

Popular posts from this blog

javascript - How to update a get parameter in a url with jquery -

amazon web services - How to determine the state of an AWS instance -

bitmap - Android load image into imageview efficiently -