Expression.Block Yöntem

Tanım

bir BlockExpressionoluşturur.

Aşırı Yüklemeler

Block(Type, IEnumerable<ParameterExpression>, IEnumerable<Expression>)

Verilen değişkenleri ve ifadeleri içeren bir BlockExpression oluşturur.

Block(Expression, Expression, Expression)

Üç ifade içeren ve değişkeni olmayan bir BlockExpression oluşturur.

Block(Expression, Expression, Expression, Expression, Expression)

Beş ifade içeren ve değişkeni olmayan bir BlockExpression oluşturur.

Block(Type, IEnumerable<ParameterExpression>, Expression[])

Verilen değişkenleri ve ifadeleri içeren bir BlockExpression oluşturur.

Block(Type, Expression[])

Verilen ifadeleri içeren, değişken içermeyen ve belirli sonuç türüne sahip bir BlockExpression oluşturur.

Block(Expression, Expression, Expression, Expression)

Dört ifade içeren ve değişkeni olmayan bir BlockExpression oluşturur.

Block(Expression, Expression)

İki ifade içeren ve değişkeni olmayan bir BlockExpression oluşturur.

Block(IEnumerable<ParameterExpression>, Expression[])

Verilen değişkenleri ve ifadeleri içeren bir BlockExpression oluşturur.

Block(IEnumerable<ParameterExpression>, IEnumerable<Expression>)

Verilen değişkenleri ve ifadeleri içeren bir BlockExpression oluşturur.

Block(Expression[])

Verilen ifadeleri içeren ve değişkeni olmayan bir BlockExpression oluşturur.

Block(IEnumerable<Expression>)

Verilen ifadeleri içeren ve değişkeni olmayan bir BlockExpression oluşturur.

Block(Type, IEnumerable<Expression>)

Verilen ifadeleri içeren, değişken içermeyen ve belirli sonuç türüne sahip bir BlockExpression oluşturur.

Block(Type, IEnumerable<ParameterExpression>, IEnumerable<Expression>)

Kaynak:
BlockExpression.cs
Kaynak:
BlockExpression.cs
Kaynak:
BlockExpression.cs

Verilen değişkenleri ve ifadeleri içeren bir BlockExpression oluşturur.

public static System.Linq.Expressions.BlockExpression Block (Type type, System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression> variables, System.Collections.Generic.IEnumerable<System.Linq.Expressions.Expression> expressions);
public static System.Linq.Expressions.BlockExpression Block (Type type, System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression>? variables, System.Collections.Generic.IEnumerable<System.Linq.Expressions.Expression> expressions);

Parametreler

type
Type

Bloğun sonuç türü.

variables
IEnumerable<ParameterExpression>

Bloktaki değişkenler.

expressions
IEnumerable<Expression>

Bloktaki ifadeler.

Döndürülenler

Oluşturulan BlockExpression.

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Block(Expression, Expression, Expression)

Kaynak:
BlockExpression.cs
Kaynak:
BlockExpression.cs
Kaynak:
BlockExpression.cs

Üç ifade içeren ve değişkeni olmayan bir BlockExpression oluşturur.

public static System.Linq.Expressions.BlockExpression Block (System.Linq.Expressions.Expression arg0, System.Linq.Expressions.Expression arg1, System.Linq.Expressions.Expression arg2);

Parametreler

arg0
Expression

Bloktaki ilk ifade.

arg1
Expression

Bloktaki ikinci ifade.

arg2
Expression

Bloktaki üçüncü ifade.

Döndürülenler

Oluşturulan BlockExpression.

Açıklamalar

Blok ifadesi yürütürken, bloktaki son ifadenin değerini döndürür.

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Block(Expression, Expression, Expression, Expression, Expression)

Kaynak:
BlockExpression.cs
Kaynak:
BlockExpression.cs
Kaynak:
BlockExpression.cs

Beş ifade içeren ve değişkeni olmayan bir BlockExpression oluşturur.

public static System.Linq.Expressions.BlockExpression Block (System.Linq.Expressions.Expression arg0, System.Linq.Expressions.Expression arg1, System.Linq.Expressions.Expression arg2, System.Linq.Expressions.Expression arg3, System.Linq.Expressions.Expression arg4);

Parametreler

arg0
Expression

Bloktaki ilk ifade.

arg1
Expression

Bloktaki ikinci ifade.

arg2
Expression

Bloktaki üçüncü ifade.

arg3
Expression

Bloktaki dördüncü ifade.

arg4
Expression

Bloktaki beşinci ifade.

Döndürülenler

Oluşturulan BlockExpression.

Açıklamalar

Blok ifadesi yürütürken, bloktaki son ifadenin değerini döndürür.

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Block(Type, IEnumerable<ParameterExpression>, Expression[])

Kaynak:
BlockExpression.cs
Kaynak:
BlockExpression.cs
Kaynak:
BlockExpression.cs

Verilen değişkenleri ve ifadeleri içeren bir BlockExpression oluşturur.

public static System.Linq.Expressions.BlockExpression Block (Type type, System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression> variables, params System.Linq.Expressions.Expression[] expressions);
public static System.Linq.Expressions.BlockExpression Block (Type type, System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression>? variables, params System.Linq.Expressions.Expression[] expressions);

Parametreler

type
Type

Bloğun sonuç türü.

variables
IEnumerable<ParameterExpression>

Bloktaki değişkenler.

expressions
Expression[]

Bloktaki ifadeler.

Döndürülenler

Oluşturulan BlockExpression.

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Block(Type, Expression[])

Kaynak:
BlockExpression.cs
Kaynak:
BlockExpression.cs
Kaynak:
BlockExpression.cs

Verilen ifadeleri içeren, değişken içermeyen ve belirli sonuç türüne sahip bir BlockExpression oluşturur.

public static System.Linq.Expressions.BlockExpression Block (Type type, params System.Linq.Expressions.Expression[] expressions);

Parametreler

type
Type

Bloğun sonuç türü.

expressions
Expression[]

Bloktaki ifadeler.

Döndürülenler

Oluşturulan BlockExpression.

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Block(Expression, Expression, Expression, Expression)

Kaynak:
BlockExpression.cs
Kaynak:
BlockExpression.cs
Kaynak:
BlockExpression.cs

Dört ifade içeren ve değişkeni olmayan bir BlockExpression oluşturur.

public static System.Linq.Expressions.BlockExpression Block (System.Linq.Expressions.Expression arg0, System.Linq.Expressions.Expression arg1, System.Linq.Expressions.Expression arg2, System.Linq.Expressions.Expression arg3);

Parametreler

arg0
Expression

Bloktaki ilk ifade.

arg1
Expression

Bloktaki ikinci ifade.

arg2
Expression

Bloktaki üçüncü ifade.

arg3
Expression

Bloktaki dördüncü ifade.

Döndürülenler

Oluşturulan BlockExpression.

Açıklamalar

Blok ifadesi yürütürken, bloktaki son ifadenin değerini döndürür.

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Block(Expression, Expression)

Kaynak:
BlockExpression.cs
Kaynak:
BlockExpression.cs
Kaynak:
BlockExpression.cs

İki ifade içeren ve değişkeni olmayan bir BlockExpression oluşturur.

public static System.Linq.Expressions.BlockExpression Block (System.Linq.Expressions.Expression arg0, System.Linq.Expressions.Expression arg1);

Parametreler

arg0
Expression

Bloktaki ilk ifade.

arg1
Expression

Bloktaki ikinci ifade.

Döndürülenler

Oluşturulan BlockExpression.

Açıklamalar

Blok ifadesi yürütürken, bloktaki son ifadenin değerini döndürür.

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Block(IEnumerable<ParameterExpression>, Expression[])

Kaynak:
BlockExpression.cs
Kaynak:
BlockExpression.cs
Kaynak:
BlockExpression.cs

Verilen değişkenleri ve ifadeleri içeren bir BlockExpression oluşturur.

public static System.Linq.Expressions.BlockExpression Block (System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression> variables, params System.Linq.Expressions.Expression[] expressions);
public static System.Linq.Expressions.BlockExpression Block (System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression>? variables, params System.Linq.Expressions.Expression[] expressions);

Parametreler

variables
IEnumerable<ParameterExpression>

Bloktaki değişkenler.

expressions
Expression[]

Bloktaki ifadeler.

Döndürülenler

Oluşturulan BlockExpression.

Açıklamalar

Blok ifadesi yürütürken, bloktaki son ifadenin değerini döndürür.

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Block(IEnumerable<ParameterExpression>, IEnumerable<Expression>)

Kaynak:
BlockExpression.cs
Kaynak:
BlockExpression.cs
Kaynak:
BlockExpression.cs

Verilen değişkenleri ve ifadeleri içeren bir BlockExpression oluşturur.

public static System.Linq.Expressions.BlockExpression Block (System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression> variables, System.Collections.Generic.IEnumerable<System.Linq.Expressions.Expression> expressions);
public static System.Linq.Expressions.BlockExpression Block (System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression>? variables, System.Collections.Generic.IEnumerable<System.Linq.Expressions.Expression> expressions);

Parametreler

variables
IEnumerable<ParameterExpression>

Bloktaki değişkenler.

expressions
IEnumerable<Expression>

Bloktaki ifadeler.

Döndürülenler

Oluşturulan BlockExpression.

Örnekler

Aşağıdaki kod örneği, bir blok ifadesine parametre geçirmeyi ve bu parametreyi bir blok içinde işlemeyi gösterir.

// Add the following directive to your file:
// using System.Linq.Expressions;

// This block has a parameter expression
// that represents a variable within the block scope.
// It assigns a value to the variable,
// and then adds a constant to the assigned value.

ParameterExpression varExpr = Expression.Variable(typeof(int), "sampleVar");
BlockExpression blockExpr = Expression.Block(
    new ParameterExpression[] { varExpr },
    Expression.Assign(varExpr, Expression.Constant(1)),
    Expression.Add(varExpr, Expression.Constant(5))
);

// Print out the expressions from the block expression.
Console.WriteLine("The expressions from the block expression:");
foreach (var expr in blockExpr.Expressions)
    Console.WriteLine(expr.ToString());

Console.WriteLine("The result of executing the expression tree:");
// The following statement first creates an expression tree,
// then compiles it, and then executes it.
Console.WriteLine(
    Expression.Lambda<Func<int>>(blockExpr).Compile()());

// This code example produces the following output:
// The expressions from the block expression:
// (sampleVar = 1)
// (sampleVar + 5)
// The result of executing the expression tree:
// 6

Açıklamalar

Blok ifadesi yürütürken, bloktaki son ifadenin değerini döndürür.

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Block(Expression[])

Kaynak:
BlockExpression.cs
Kaynak:
BlockExpression.cs
Kaynak:
BlockExpression.cs

Verilen ifadeleri içeren ve değişkeni olmayan bir BlockExpression oluşturur.

public static System.Linq.Expressions.BlockExpression Block (params System.Linq.Expressions.Expression[] expressions);

Parametreler

expressions
Expression[]

Bloktaki ifadeler.

Döndürülenler

Oluşturulan BlockExpression.

Örnekler

Aşağıdaki kod örneğinde blok ifadesinin nasıl oluşturulacağı gösterilmektedir. Blok ifadesi iki MethodCallExpression nesneden ve bir nesneden ConstantExpression oluşur.

// Add the following directive to your file:
// using System.Linq.Expressions;

// The block expression allows for executing several expressions sequentually.
// When the block expression is executed,
// it returns the value of the last expression in the sequence.
BlockExpression blockExpr = Expression.Block(
    Expression.Call(
        null,
        typeof(Console).GetMethod("Write", new Type[] { typeof(String) }),
        Expression.Constant("Hello ")
       ),
    Expression.Call(
        null,
        typeof(Console).GetMethod("WriteLine", new Type[] { typeof(String) }),
        Expression.Constant("World!")
        ),
    Expression.Constant(42)
);

Console.WriteLine("The result of executing the expression tree:");
// The following statement first creates an expression tree,
// then compiles it, and then executes it.
var result = Expression.Lambda<Func<int>>(blockExpr).Compile()();

// Print out the expressions from the block expression.
Console.WriteLine("The expressions from the block expression:");
foreach (var expr in blockExpr.Expressions)
    Console.WriteLine(expr.ToString());

// Print out the result of the tree execution.
Console.WriteLine("The return value of the block expression:");
Console.WriteLine(result);

// This code example produces the following output:
//
// The result of executing the expression tree:
// Hello World!

// The expressions from the block expression:
// Write("Hello ")
// WriteLine("World!")
// 42

// The return value of the block expression:
// 42

Açıklamalar

Blok ifadesi yürütürken, bloktaki son ifadenin değerini döndürür.

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Block(IEnumerable<Expression>)

Kaynak:
BlockExpression.cs
Kaynak:
BlockExpression.cs
Kaynak:
BlockExpression.cs

Verilen ifadeleri içeren ve değişkeni olmayan bir BlockExpression oluşturur.

public static System.Linq.Expressions.BlockExpression Block (System.Collections.Generic.IEnumerable<System.Linq.Expressions.Expression> expressions);

Parametreler

expressions
IEnumerable<Expression>

Bloktaki ifadeler.

Döndürülenler

Oluşturulan BlockExpression.

Açıklamalar

Blok ifadesi yürütürken, bloktaki son ifadenin değerini döndürür.

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Block(Type, IEnumerable<Expression>)

Kaynak:
BlockExpression.cs
Kaynak:
BlockExpression.cs
Kaynak:
BlockExpression.cs

Verilen ifadeleri içeren, değişken içermeyen ve belirli sonuç türüne sahip bir BlockExpression oluşturur.

public static System.Linq.Expressions.BlockExpression Block (Type type, System.Collections.Generic.IEnumerable<System.Linq.Expressions.Expression> expressions);

Parametreler

type
Type

Bloğun sonuç türü.

expressions
IEnumerable<Expression>

Bloktaki ifadeler.

Döndürülenler

Oluşturulan BlockExpression.

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0