LINQ in C#
LINQ (Language Integrated Query) is a feature in C# that allows a program to query data from various data sources such as arrays, collections, databases, etc. using a common syntax. Here's an example code that demonstrates how to use LINQ to query an array:
int[] numbers = { 1, 2, 3, 4, 5 };
var evenNumbers = from num in numbers
where num % 2 == 0
select num;
foreach (var num in evenNumbers)
{
Console.WriteLine(num); // prints 2 4
}
No comments:
Post a Comment