Wednesday 15 July 2015

Simplest way to filter value from generic List in C# using LINQ -


I have two classes that are the first person person , and the second is student list and search for all students , which is more than 7 I came up with the following solution:

  class person {public string name {get; Set;}} Class student: person {public decimal grade {receipt; Set;}} class program {static zero main (string [] args) {list & lt; Person & gt; People = new list & lt; Person & gt; (); People.Add (new person () {name = "jon"}); People Add (New Student () {name = "Joe", Grade = 6}); People Add (New Student () {name = "Jane", Grade = 8}); People Where (Representative (person) (student student = Student; return student! = Null and student; grade & gt; 7;}); }}   

Any easy way to filter this list?

Only improvement that I see is using OfType , like

  var results = people. Optty Type & lt; Students & gt; (). Where (S => grade> 7);   

... and my syntax is simple ... but it is in view of the viewer

No comments:

Post a Comment