Linq Query Operators
Category | Query Operator |
---|---|
Filter from a collection | Where, OfType |
Sorting a collection | OrderBy, OrderByDescending, ThenBy, ThenByDescending, Reverse |
Grouping Data | GroupBy, ToLookup |
Join Data | GroupJoin, Join |
Selecting Data | Select, SelectMany |
Aggregate functions | Aggregate, Average, Count, LongCount, Max, Min, Sum |
Conditions | All, Any, Contains |
Finding Record | ElementAt, ElementAtOrDefault, First, FirstOrDefault, Last, LastOrDefault, Single, SingleOrDefault |
Set | Distinct, Except, Intersect, Union |
Partitioning | Skip, SkipWhile, Take, TakeWhile |
Concatenation | Concat |
Equality | SequenceEqual |
Generation | DefaultEmpty, Empty, Range, Repeat |
Conversion | AsEnumerable, AsQueryable, Cast, ToArray, ToDictionary, ToList |
Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
using System.Collections.Generic; | |
class Program | |
{ | |
IList<Student> studentList = new List<Student>() { | |
new Student() { StudentID = 1, StudentName = "Zahid", Age = 13} , | |
new Student() { StudentID = 2, StudentName = "Moin", Age = 21 } , | |
new Student() { StudentID = 3, StudentName = "Arsalan", Age = 18 } , | |
new Student() { StudentID = 4, StudentName = "Kamran" , Age = 20} , | |
new Student() { StudentID = 5, StudentName = "Irfan" , Age = 15 } | |
}; | |
var teenager=studentList.Where(s=>{ | |
return s.Age <20; | |
} | |
); | |
foreach(var teen in teenager) | |
Console.WriteLine(teen.StudentName+" is a Teenager"); | |
} | |
} | |
class Student{ | |
public int StudentID {get;set;} | |
public string StudentName{get;set;} | |
public int Age {get;set;} | |
} |