Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C#

filtering and transformations: practical reference

filtering and transformations: practical reference: Filtering retains selected elements, while transformation creates a new data shape.

Version: C# language and .NET 10 reference runtime

Syntax

// filtering transformations

Filtering retains selected elements, while transformation creates a new data shape.

Compose Where and Select into a readable pipeline and materialize only at the required boundary.

Selectors with side effects run on every enumeration.

An empty source yields an empty result, and a predicate exception stops the pipeline.

The complete program actually uses filtering and transformations; its exact expected stdout is 4,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 result = new[] { 1, 2, 3 }.Where(value => value > 1).Select(value => value * 2); Console.WriteLine(string.Join(",", result));

Result

4,6

The complete program actually uses `filtering and transformations`; its exact expected stdout is `4,6`.

Sources