The query operator and the Linq operator of Linq.
Linq has expression syntax and method calling syntax. Both can be used in combination. Expression syntax looks clear, and the syntax for calling methods provides more functions. This article describes expression syntax. For method syntax, see the extension methods in namespaces such as System. Linq. Linq can be used only for classes that implement the IEnumerable or IEnumerable <T> interface, that is, all classes that can use foreach can use linq.
Note that there are some differences between the 3.5 and 4.0 versions of the linq keyword. The following is based on 4.0.
1. Projection Operator
Select: projection of values in the set and sequence. From c in contact select c;
2. Restricted Operators
Where: Same as where in SQL statements, it is used to filter data. From c in contact where c. Lastname = "Josn" select c;
3. Sorting Operators
OrderBy: sorts the return values in ascending order. From c in contact orderby c. Lastname select c;
OrderBy Descending: sorts the return values in Descending order. From c in contact orderby c. Lastname descending select c;
3. Join Operators
Join: You can connect multiple data sources. From c in contact join e in employee on c. ID equals e. ContactID select c;
4. grouping operators
Groupby: groups values in the data source based on a specific value. Similar to group by in SQL statements. From c in contact groupby (c => c. Nationality) select c;