Junior — Middle
What are the different types of methods in LINQ?
sobes.tech AI
Answer from AI
In LINQ (Language Integrated Query) in C#, there are several main types of methods:
-
Projection operators — for example,
Select,SelectMany, which transform sequence elements. -
Filtering operators — for example,
Where, which select elements based on a condition. -
Ordering operators —
OrderBy,OrderByDescending,ThenBy. -
Aggregation methods —
Count,Sum,Average,Min,Max. -
Set operations —
Distinct,Union,Intersect,Except. -
Grouping operators —
GroupBy. -
Element access operators —
First,FirstOrDefault,Single,SingleOrDefault,Last. -
Quantifiers —
Any,All.
Example of usage:
var numbers = new List<int> {1, 2, 3, 4, 5};
var evenNumbers = numbers.Where(n => n % 2 == 0).Select(n => n * 10);
foreach(var num in evenNumbers)
{
Console.WriteLine(num); // 20, 40
}