Base de conhecimentoCentro de Exames
PT · PTPortuguês (Portugal)
Escolher idioma13

CKTIS / C#

filtering and transformations: referência prática

filtering and transformations: referência prática: A filtragem conserva elementos escolhidos, enquanto a transformação cria uma nova forma dos dados.

Versão: C# language and .NET 10 reference runtime

Sintaxe

// filtering transformations

A filtragem conserva elementos escolhidos, enquanto a transformação cria uma nova forma dos dados.

Compõe Where e Select num pipeline legível e materializa apenas no limite necessário.

Seletores com efeitos secundários executam em cada enumeração.

Uma origem vazia dá resultado vazio e uma exceção do predicado para o pipeline.

O programa completo usa realmente filtering and transformations; o stdout exato esperado é 4,6.

Exemplos

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));

Resultado

4,6

O programa completo usa realmente `filtering and transformations`; o stdout exato esperado é `4,6`.

Fontes