Expression.Block Metode
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
BlockExpressionMembuat .
Overload
Block(Type, IEnumerable<ParameterExpression>, IEnumerable<Expression>) |
Membuat yang BlockExpression berisi variabel dan ekspresi yang diberikan. |
Block(Expression, Expression, Expression) |
Membuat yang BlockExpression berisi tiga ekspresi dan tidak memiliki variabel. |
Block(Expression, Expression, Expression, Expression, Expression) |
BlockExpression Membuat yang berisi lima ekspresi dan tidak memiliki variabel. |
Block(Type, IEnumerable<ParameterExpression>, Expression[]) |
Membuat yang BlockExpression berisi variabel dan ekspresi yang diberikan. |
Block(Type, Expression[]) |
BlockExpression Membuat yang berisi ekspresi yang diberikan, tidak memiliki variabel dan memiliki jenis hasil tertentu. |
Block(Expression, Expression, Expression, Expression) |
BlockExpression Membuat yang berisi empat ekspresi dan tidak memiliki variabel. |
Block(Expression, Expression) |
Membuat yang BlockExpression berisi dua ekspresi dan tidak memiliki variabel. |
Block(IEnumerable<ParameterExpression>, Expression[]) |
Membuat yang BlockExpression berisi variabel dan ekspresi yang diberikan. |
Block(IEnumerable<ParameterExpression>, IEnumerable<Expression>) |
Membuat yang BlockExpression berisi variabel dan ekspresi yang diberikan. |
Block(Expression[]) |
Membuat yang BlockExpression berisi ekspresi yang diberikan dan tidak memiliki variabel. |
Block(IEnumerable<Expression>) |
Membuat yang BlockExpression berisi ekspresi yang diberikan dan tidak memiliki variabel. |
Block(Type, IEnumerable<Expression>) |
BlockExpression Membuat yang berisi ekspresi yang diberikan, tidak memiliki variabel dan memiliki jenis hasil tertentu. |
Block(Type, IEnumerable<ParameterExpression>, IEnumerable<Expression>)
- Sumber:
- BlockExpression.cs
- Sumber:
- BlockExpression.cs
- Sumber:
- BlockExpression.cs
Membuat yang BlockExpression berisi variabel dan ekspresi yang diberikan.
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);
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);
static member Block : Type * seq<System.Linq.Expressions.ParameterExpression> * seq<System.Linq.Expressions.Expression> -> System.Linq.Expressions.BlockExpression
Public Shared Function Block (type As Type, variables As IEnumerable(Of ParameterExpression), expressions As IEnumerable(Of Expression)) As BlockExpression
Parameter
- type
- Type
Jenis hasil blok.
- variables
- IEnumerable<ParameterExpression>
Variabel di blok .
- expressions
- IEnumerable<Expression>
Ekspresi di blok .
Mengembalikan
yang dibuat BlockExpression.
Berlaku untuk
Block(Expression, Expression, Expression)
- Sumber:
- BlockExpression.cs
- Sumber:
- BlockExpression.cs
- Sumber:
- BlockExpression.cs
Membuat yang BlockExpression berisi tiga ekspresi dan tidak memiliki variabel.
public:
static System::Linq::Expressions::BlockExpression ^ Block(System::Linq::Expressions::Expression ^ arg0, System::Linq::Expressions::Expression ^ arg1, System::Linq::Expressions::Expression ^ arg2);
public static System.Linq.Expressions.BlockExpression Block (System.Linq.Expressions.Expression arg0, System.Linq.Expressions.Expression arg1, System.Linq.Expressions.Expression arg2);
static member Block : System.Linq.Expressions.Expression * System.Linq.Expressions.Expression * System.Linq.Expressions.Expression -> System.Linq.Expressions.BlockExpression
Public Shared Function Block (arg0 As Expression, arg1 As Expression, arg2 As Expression) As BlockExpression
Parameter
- arg0
- Expression
Ekspresi pertama di blok .
- arg1
- Expression
Ekspresi kedua di blok .
- arg2
- Expression
Ekspresi ketiga di blok .
Mengembalikan
yang dibuat BlockExpression.
Keterangan
Saat ekspresi blok dijalankan, ekspresi blok mengembalikan nilai ekspresi terakhir di blok .
Berlaku untuk
Block(Expression, Expression, Expression, Expression, Expression)
- Sumber:
- BlockExpression.cs
- Sumber:
- BlockExpression.cs
- Sumber:
- BlockExpression.cs
BlockExpression Membuat yang berisi lima ekspresi dan tidak memiliki variabel.
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);
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);
static member Block : System.Linq.Expressions.Expression * System.Linq.Expressions.Expression * System.Linq.Expressions.Expression * System.Linq.Expressions.Expression * System.Linq.Expressions.Expression -> System.Linq.Expressions.BlockExpression
Public Shared Function Block (arg0 As Expression, arg1 As Expression, arg2 As Expression, arg3 As Expression, arg4 As Expression) As BlockExpression
Parameter
- arg0
- Expression
Ekspresi pertama di blok .
- arg1
- Expression
Ekspresi kedua di blok .
- arg2
- Expression
Ekspresi ketiga di blok .
- arg3
- Expression
Ekspresi keempat dalam blok .
- arg4
- Expression
Ekspresi kelima di blok .
Mengembalikan
yang dibuat BlockExpression.
Keterangan
Saat ekspresi blok dijalankan, ekspresi blok mengembalikan nilai ekspresi terakhir di blok .
Berlaku untuk
Block(Type, IEnumerable<ParameterExpression>, Expression[])
- Sumber:
- BlockExpression.cs
- Sumber:
- BlockExpression.cs
- Sumber:
- BlockExpression.cs
Membuat yang BlockExpression berisi variabel dan ekspresi yang diberikan.
public:
static System::Linq::Expressions::BlockExpression ^ Block(Type ^ type, System::Collections::Generic::IEnumerable<System::Linq::Expressions::ParameterExpression ^> ^ variables, ... cli::array <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);
public static System.Linq.Expressions.BlockExpression Block (Type type, System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression>? variables, params System.Linq.Expressions.Expression[] expressions);
static member Block : Type * seq<System.Linq.Expressions.ParameterExpression> * System.Linq.Expressions.Expression[] -> System.Linq.Expressions.BlockExpression
Public Shared Function Block (type As Type, variables As IEnumerable(Of ParameterExpression), ParamArray expressions As Expression()) As BlockExpression
Parameter
- type
- Type
Jenis hasil blok.
- variables
- IEnumerable<ParameterExpression>
Variabel di blok .
- expressions
- Expression[]
Ekspresi di blok .
Mengembalikan
yang dibuat BlockExpression.
Berlaku untuk
Block(Type, Expression[])
- Sumber:
- BlockExpression.cs
- Sumber:
- BlockExpression.cs
- Sumber:
- BlockExpression.cs
BlockExpression Membuat yang berisi ekspresi yang diberikan, tidak memiliki variabel dan memiliki jenis hasil tertentu.
public:
static System::Linq::Expressions::BlockExpression ^ Block(Type ^ type, ... cli::array <System::Linq::Expressions::Expression ^> ^ expressions);
public static System.Linq.Expressions.BlockExpression Block (Type type, params System.Linq.Expressions.Expression[] expressions);
static member Block : Type * System.Linq.Expressions.Expression[] -> System.Linq.Expressions.BlockExpression
Public Shared Function Block (type As Type, ParamArray expressions As Expression()) As BlockExpression
Parameter
- type
- Type
Jenis hasil blok.
- expressions
- Expression[]
Ekspresi di blok .
Mengembalikan
yang dibuat BlockExpression.
Berlaku untuk
Block(Expression, Expression, Expression, Expression)
- Sumber:
- BlockExpression.cs
- Sumber:
- BlockExpression.cs
- Sumber:
- BlockExpression.cs
BlockExpression Membuat yang berisi empat ekspresi dan tidak memiliki variabel.
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);
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);
static member Block : System.Linq.Expressions.Expression * System.Linq.Expressions.Expression * System.Linq.Expressions.Expression * System.Linq.Expressions.Expression -> System.Linq.Expressions.BlockExpression
Public Shared Function Block (arg0 As Expression, arg1 As Expression, arg2 As Expression, arg3 As Expression) As BlockExpression
Parameter
- arg0
- Expression
Ekspresi pertama di blok .
- arg1
- Expression
Ekspresi kedua di blok .
- arg2
- Expression
Ekspresi ketiga di blok .
- arg3
- Expression
Ekspresi keempat dalam blok .
Mengembalikan
yang dibuat BlockExpression.
Keterangan
Saat ekspresi blok dijalankan, ekspresi blok mengembalikan nilai ekspresi terakhir di blok .
Berlaku untuk
Block(Expression, Expression)
- Sumber:
- BlockExpression.cs
- Sumber:
- BlockExpression.cs
- Sumber:
- BlockExpression.cs
Membuat yang BlockExpression berisi dua ekspresi dan tidak memiliki variabel.
public:
static System::Linq::Expressions::BlockExpression ^ Block(System::Linq::Expressions::Expression ^ arg0, System::Linq::Expressions::Expression ^ arg1);
public static System.Linq.Expressions.BlockExpression Block (System.Linq.Expressions.Expression arg0, System.Linq.Expressions.Expression arg1);
static member Block : System.Linq.Expressions.Expression * System.Linq.Expressions.Expression -> System.Linq.Expressions.BlockExpression
Public Shared Function Block (arg0 As Expression, arg1 As Expression) As BlockExpression
Parameter
- arg0
- Expression
Ekspresi pertama di blok .
- arg1
- Expression
Ekspresi kedua di blok .
Mengembalikan
yang dibuat BlockExpression.
Keterangan
Saat ekspresi blok dijalankan, ekspresi blok mengembalikan nilai ekspresi terakhir di blok .
Berlaku untuk
Block(IEnumerable<ParameterExpression>, Expression[])
- Sumber:
- BlockExpression.cs
- Sumber:
- BlockExpression.cs
- Sumber:
- BlockExpression.cs
Membuat yang BlockExpression berisi variabel dan ekspresi yang diberikan.
public:
static System::Linq::Expressions::BlockExpression ^ Block(System::Collections::Generic::IEnumerable<System::Linq::Expressions::ParameterExpression ^> ^ variables, ... cli::array <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);
public static System.Linq.Expressions.BlockExpression Block (System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression>? variables, params System.Linq.Expressions.Expression[] expressions);
static member Block : seq<System.Linq.Expressions.ParameterExpression> * System.Linq.Expressions.Expression[] -> System.Linq.Expressions.BlockExpression
Public Shared Function Block (variables As IEnumerable(Of ParameterExpression), ParamArray expressions As Expression()) As BlockExpression
Parameter
- variables
- IEnumerable<ParameterExpression>
Variabel di blok .
- expressions
- Expression[]
Ekspresi di blok .
Mengembalikan
yang dibuat BlockExpression.
Keterangan
Saat ekspresi blok dijalankan, ekspresi blok mengembalikan nilai ekspresi terakhir di blok .
Berlaku untuk
Block(IEnumerable<ParameterExpression>, IEnumerable<Expression>)
- Sumber:
- BlockExpression.cs
- Sumber:
- BlockExpression.cs
- Sumber:
- BlockExpression.cs
Membuat yang BlockExpression berisi variabel dan ekspresi yang diberikan.
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);
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);
static member Block : seq<System.Linq.Expressions.ParameterExpression> * seq<System.Linq.Expressions.Expression> -> System.Linq.Expressions.BlockExpression
Public Shared Function Block (variables As IEnumerable(Of ParameterExpression), expressions As IEnumerable(Of Expression)) As BlockExpression
Parameter
- variables
- IEnumerable<ParameterExpression>
Variabel di blok .
- expressions
- IEnumerable<Expression>
Ekspresi di blok .
Mengembalikan
yang dibuat BlockExpression.
Contoh
Contoh kode berikut menunjukkan cara meneruskan parameter ke ekspresi blok dan memproses parameter ini dalam blok.
// 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
' Add the following directive to your file:
' Imports 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.
Dim varExpr As ParameterExpression = Expression.Variable(GetType(Integer), "sampleVar")
Dim blockExpr As BlockExpression = Expression.Block(
New ParameterExpression() {varExpr},
Expression.Assign(varExpr, Expression.Constant(1)),
Expression.Add(varExpr, Expression.Constant(5))
)
' Print the expressions from the block expression.
Console.WriteLine("The expressions from the block expression:")
For Each expr In blockExpr.Expressions
Console.WriteLine(expr.ToString())
Next
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(Of Func(Of Integer))(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
Keterangan
Saat ekspresi blok dijalankan, ekspresi blok mengembalikan nilai ekspresi terakhir di blok .
Berlaku untuk
Block(Expression[])
- Sumber:
- BlockExpression.cs
- Sumber:
- BlockExpression.cs
- Sumber:
- BlockExpression.cs
Membuat yang BlockExpression berisi ekspresi yang diberikan dan tidak memiliki variabel.
public:
static System::Linq::Expressions::BlockExpression ^ Block(... cli::array <System::Linq::Expressions::Expression ^> ^ expressions);
public static System.Linq.Expressions.BlockExpression Block (params System.Linq.Expressions.Expression[] expressions);
static member Block : System.Linq.Expressions.Expression[] -> System.Linq.Expressions.BlockExpression
Public Shared Function Block (ParamArray expressions As Expression()) As BlockExpression
Parameter
- expressions
- Expression[]
Ekspresi di blok .
Mengembalikan
yang dibuat BlockExpression.
Contoh
Contoh kode berikut menunjukkan cara membuat ekspresi blok. Ekspresi blok terdiri dari dua MethodCallExpression objek dan satu ConstantExpression objek.
// 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
' Add the following directive to your file:
' Imports System.Linq.Expressions
' The block expression enables you to execute several expressions sequentually.
' When the block expression is executed,
' it returns the value of the last expression in the sequence.
Dim blockExpr As BlockExpression = Expression.Block(
Expression.Call(
Nothing,
GetType(Console).GetMethod("Write", New Type() {GetType(String)}),
Expression.Constant("Hello ")
),
Expression.Call(
Nothing,
GetType(Console).GetMethod("WriteLine", New Type() {GetType(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.
Dim result = Expression.Lambda(Of Func(Of Integer))(blockExpr).Compile()()
' Print the expressions from the block expression.
Console.WriteLine("The expressions from the block expression:")
For Each expr In blockExpr.Expressions
Console.WriteLine(expr.ToString())
Next
' Print 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
Keterangan
Saat ekspresi blok dijalankan, ekspresi blok mengembalikan nilai ekspresi terakhir di blok .
Berlaku untuk
Block(IEnumerable<Expression>)
- Sumber:
- BlockExpression.cs
- Sumber:
- BlockExpression.cs
- Sumber:
- BlockExpression.cs
Membuat yang BlockExpression berisi ekspresi yang diberikan dan tidak memiliki variabel.
public:
static System::Linq::Expressions::BlockExpression ^ Block(System::Collections::Generic::IEnumerable<System::Linq::Expressions::Expression ^> ^ expressions);
public static System.Linq.Expressions.BlockExpression Block (System.Collections.Generic.IEnumerable<System.Linq.Expressions.Expression> expressions);
static member Block : seq<System.Linq.Expressions.Expression> -> System.Linq.Expressions.BlockExpression
Public Shared Function Block (expressions As IEnumerable(Of Expression)) As BlockExpression
Parameter
- expressions
- IEnumerable<Expression>
Ekspresi di blok .
Mengembalikan
yang dibuat BlockExpression.
Keterangan
Saat ekspresi blok dijalankan, ekspresi blok mengembalikan nilai ekspresi terakhir di blok .
Berlaku untuk
Block(Type, IEnumerable<Expression>)
- Sumber:
- BlockExpression.cs
- Sumber:
- BlockExpression.cs
- Sumber:
- BlockExpression.cs
BlockExpression Membuat yang berisi ekspresi yang diberikan, tidak memiliki variabel dan memiliki jenis hasil tertentu.
public:
static System::Linq::Expressions::BlockExpression ^ Block(Type ^ type, 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.Expression> expressions);
static member Block : Type * seq<System.Linq.Expressions.Expression> -> System.Linq.Expressions.BlockExpression
Public Shared Function Block (type As Type, expressions As IEnumerable(Of Expression)) As BlockExpression
Parameter
- type
- Type
Jenis hasil blok.
- expressions
- IEnumerable<Expression>
Ekspresi di blok .
Mengembalikan
yang dibuat BlockExpression.