Junior — Middle
Have you ever used filters in your projects?
sobes.tech AI
Answer from AI
Yes, filters are often used in C# for processing collections of data, for example, using LINQ. A filter allows selecting only those elements from a set that meet a certain condition.
Example of using a filter with LINQ:
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
static void Main()
{
List<int> numbers = new List<int> {1, 2, 3, 4, 5, 6};
// Filter only even numbers
var evenNumbers = numbers.Where(n => n % 2 == 0);
foreach (var num in evenNumbers)
{
Console.WriteLine(num); // Will output 2, 4, 6
}
}
}
Filters are useful for simplifying data processing and improving code readability.