Introduction
LINQ helps you work with data easily and clearly. It lets you ask questions about data like a friend would, without writing lots of code.
Jump into concepts and practice - no test required
LINQ helps you work with data easily and clearly. It lets you ask questions about data like a friend would, without writing lots of code.
var result = from item in collection
where item.Property == value
select item;var numbers = new int[] {1, 2, 3, 4, 5}; var evenNumbers = from n in numbers where n % 2 == 0 select n;
var names = new List<string> {"Anna", "Bob", "Cathy"}; var shortNames = from name in names where name.Length <= 3 select name;
This program uses LINQ to find numbers bigger than 20 and prints them.
using System; using System.Linq; class Program { static void Main() { int[] numbers = {10, 15, 20, 25, 30}; var bigNumbers = from num in numbers where num > 20 select num; Console.WriteLine("Numbers greater than 20:"); foreach (var num in bigNumbers) { Console.WriteLine(num); } } }
LINQ makes your code shorter and easier to read.
It works with many data types, so you learn one way to handle many tasks.
LINQ queries are easy to change if your needs change.
LINQ helps you work with data simply and clearly.
It uses easy words like from, where, and select to ask questions about data.
LINQ saves time and reduces mistakes when handling data.
int[] numbers = {1, 2, 3, 4, 5};
var result = from n in numbers where n > 3 select n;
foreach(var num in result) Console.Write(num + " ");var result = from x in numbers where x => 5 select x;
var students = new List<(string Name, int Score)>
{
("Alice", 85), ("Bob", 65), ("Charlie", 90)
};
var result = ???;