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

CKTIS / C#

System.Linq.Expressions.LambdaExpression: referência prática

System.Linq.Expressions.LambdaExpression: referência prática: LambdaExpression é a base não genérica de uma árvore lambda com Body, Parameters e ReturnType.

Versão: .NET API; verified on .NET 10.0.14

Sintaxe

System.Linq.Expressions.LambdaExpression /* select a documented member or constructor */

LambdaExpression é a base não genérica de uma árvore lambda com Body, Parameters e ReturnType.

Usa-a em ferramentas reflexivas que tratam lambdas cujo tipo de delegate só é conhecido em execução.

Compile e invocação dinâmica perdem parte da verificação estática e podem estar indisponíveis com AOT.

O número e os tipos dos parâmetros têm de corresponder ao delegate ou a construção lança uma exceção.

O programa completo usa realmente System.Linq.Expressions.LambdaExpression; o stdout exato esperado é 1.

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;

LambdaExpression expression = (Expression<Func<int, int>>)(value => value * 2);
Console.WriteLine(expression.Parameters.Count);

Resultado

1

O programa completo usa realmente `System.Linq.Expressions.LambdaExpression`; o stdout exato esperado é `1`.

Fontes