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

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -