Sobes.tech
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:

  1. Projection operators — for example, Select, SelectMany, which transform sequence elements.

  2. Filtering operators — for example, Where, which select elements based on a condition.

  3. Ordering operatorsOrderBy, OrderByDescending, ThenBy.

  4. Aggregation methodsCount, Sum, Average, Min, Max.

  5. Set operationsDistinct, Union, Intersect, Except.

  6. Grouping operatorsGroupBy.

  7. Element access operatorsFirst, FirstOrDefault, Single, SingleOrDefault, Last.

  8. QuantifiersAny, 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
}