Junior — Middle
Kas saaksite loetleda ja selgitada LINQ-s kasutatavate peamiste päringutüüpide?
sobes.tech AI
Vastus AI-lt
The main types of queries in LINQ can be divided into two categories: data selection queries and data transformation queries.
-
Selection operators:
Where— filtering elements based on a condition.Select— projection, transforming elements.OrderBy/OrderByDescending— sorting.GroupBy— grouping elements by key.
-
Aggregation operators:
Count— counting elements.Sum,Average,Min,Max— calculating aggregate values.
-
Join operators:
Join— joining two sequences by key.GroupJoin— grouping with join.
-
Elementary access operators:
First,FirstOrDefault,Single,SingleOrDefault— getting the first or only element.
-
Transformation operators:
Distinct— removing duplicates.Skip,Take— skipping and selecting a certain number of elements.
Example:
var result = people
.Where(p => p.Age > 18) // filtering
.OrderBy(p => p.Name) // sorting
.Select(p => p.Name); // projection
Thus, LINQ provides a convenient and expressive syntax for working with collections and data.