Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C#

LINQ queries: practical reference

LINQ queries: practical reference: LINQ provides composable sequence operators, often with deferred execution.

Version: C# language and .NET 10 reference runtime

Syntax

// linq

LINQ provides composable sequence operators, often with deferred execution.

Build readable queries and explicitly choose terminal materialization.

An IQueryable provider may translate only part of the code and behave differently from LINQ-to-Objects.

Repeated enumeration, null, and empty sources have operator-specific behavior.

The complete program actually uses LINQ queries; its exact expected stdout is 6.

Examples

using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;

var sum = Enumerable.Range(1, 4).Where(value => value % 2 == 0).Sum(); Console.WriteLine(sum);

Result

6

The complete program actually uses `LINQ queries`; its exact expected stdout is `6`.

Sources