Skip to main content

Linq

Where, Select, OrderBy, Group

medium

Delegate

public delegate bool IsEvenDelegate(int number);

public static bool IsEven(int number)
{
return number % 2 == 0;
}

IsEvenDelegate isEvenDel = IsEven;
List<int> numbers = new List<int> { 1, 2, 3, 4, 5 };

IEnumerable<int> evenNumbers = numbers.Where(n => isEvenDel(n));

Distinct, Union, intersect

// Set operations example
var firstNames = new string[] { "John", "Jane", "Jim", "Jane" };
var lastNames = new string[] { "Doe", "Smith", "Adams", "John" };

var distinctFirstNames = firstNames.Distinct(); // "John", "Jane", "Jim"
var unionNames = firstNames.Union(lastNames); // "John", "Jane", "Jim", "Doe", "Smith", "Adams"
var intersectNames = firstNames.Intersect(lastNames); // "John"

https://www.bytehide.com/blog/linq-csharp