Expression.Block 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
BlockExpression을 만듭니다.
오버로드
Block(Type, IEnumerable<ParameterExpression>, IEnumerable<Expression>)
- Source:
- BlockExpression.cs
- Source:
- BlockExpression.cs
- Source:
- BlockExpression.cs
지정된 변수와 식이 포함된 BlockExpression을 만듭니다.
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
매개 변수
- type
- Type
블록의 결과 형식입니다.
- variables
- IEnumerable<ParameterExpression>
블록의 변수입니다.
- expressions
- IEnumerable<Expression>
블록의 식입니다.
반환
만든 BlockExpression입니다.
적용 대상
Block(Expression, Expression, Expression)
- Source:
- BlockExpression.cs
- Source:
- BlockExpression.cs
- Source:
- BlockExpression.cs
3개 식을 포함하고 변수가 없는 BlockExpression을 만듭니다.
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
매개 변수
- arg0
- Expression
블록의 첫 번째 식입니다.
- arg1
- Expression
블록의 두 번째 식입니다.
- arg2
- Expression
블록의 세 번째 식입니다.
반환
만든 BlockExpression입니다.
설명
블록 식이 실행되면 블록의 마지막 식 값을 반환합니다.
적용 대상
Block(Expression, Expression, Expression, Expression, Expression)
- Source:
- BlockExpression.cs
- Source:
- BlockExpression.cs
- Source:
- BlockExpression.cs
5개 식을 포함하고 변수가 없는 BlockExpression을 만듭니다.
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
매개 변수
- arg0
- Expression
블록의 첫 번째 식입니다.
- arg1
- Expression
블록의 두 번째 식입니다.
- arg2
- Expression
블록의 세 번째 식입니다.
- arg3
- Expression
블록의 네 번째 식입니다.
- arg4
- Expression
블록의 다섯 번째 식입니다.
반환
만든 BlockExpression입니다.
설명
블록 식이 실행되면 블록의 마지막 식 값을 반환합니다.
적용 대상
Block(Type, IEnumerable<ParameterExpression>, Expression[])
- Source:
- BlockExpression.cs
- Source:
- BlockExpression.cs
- Source:
- BlockExpression.cs
지정된 변수와 식이 포함된 BlockExpression을 만듭니다.
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
매개 변수
- type
- Type
블록의 결과 형식입니다.
- variables
- IEnumerable<ParameterExpression>
블록의 변수입니다.
- expressions
- Expression[]
블록의 식입니다.
반환
만든 BlockExpression입니다.
적용 대상
Block(Type, Expression[])
- Source:
- BlockExpression.cs
- Source:
- BlockExpression.cs
- Source:
- BlockExpression.cs
지정된 식을 포함하고 변수가 없으며 특정 결과 형식이 있는 BlockExpression을 만듭니다.
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
매개 변수
- type
- Type
블록의 결과 형식입니다.
- expressions
- Expression[]
블록의 식입니다.
반환
만든 BlockExpression입니다.
적용 대상
Block(Expression, Expression, Expression, Expression)
- Source:
- BlockExpression.cs
- Source:
- BlockExpression.cs
- Source:
- BlockExpression.cs
4개 식을 포함하고 변수가 없는 BlockExpression을 만듭니다.
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
매개 변수
- arg0
- Expression
블록의 첫 번째 식입니다.
- arg1
- Expression
블록의 두 번째 식입니다.
- arg2
- Expression
블록의 세 번째 식입니다.
- arg3
- Expression
블록의 네 번째 식입니다.
반환
만든 BlockExpression입니다.
설명
블록 식이 실행되면 블록의 마지막 식 값을 반환합니다.
적용 대상
Block(Expression, Expression)
- Source:
- BlockExpression.cs
- Source:
- BlockExpression.cs
- Source:
- BlockExpression.cs
2개 식을 포함하고 변수가 없는 BlockExpression을 만듭니다.
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
매개 변수
- arg0
- Expression
블록의 첫 번째 식입니다.
- arg1
- Expression
블록의 두 번째 식입니다.
반환
만든 BlockExpression입니다.
설명
블록 식이 실행되면 블록의 마지막 식 값을 반환합니다.
적용 대상
Block(IEnumerable<ParameterExpression>, Expression[])
- Source:
- BlockExpression.cs
- Source:
- BlockExpression.cs
- Source:
- BlockExpression.cs
지정된 변수와 식이 포함된 BlockExpression을 만듭니다.
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
매개 변수
- variables
- IEnumerable<ParameterExpression>
블록의 변수입니다.
- expressions
- Expression[]
블록의 식입니다.
반환
만든 BlockExpression입니다.
설명
블록 식이 실행되면 블록의 마지막 식 값을 반환합니다.
적용 대상
Block(IEnumerable<ParameterExpression>, IEnumerable<Expression>)
- Source:
- BlockExpression.cs
- Source:
- BlockExpression.cs
- Source:
- BlockExpression.cs
지정된 변수와 식이 포함된 BlockExpression을 만듭니다.
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
매개 변수
- variables
- IEnumerable<ParameterExpression>
블록의 변수입니다.
- expressions
- IEnumerable<Expression>
블록의 식입니다.
반환
만든 BlockExpression입니다.
예제
다음 코드 예제에서는 블록 식에 매개 변수를 전달 하 고 블록 내에서이 매개 변수를 처리 하는 방법을 보여 있습니다.
// 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
설명
블록 식이 실행되면 블록의 마지막 식 값을 반환합니다.
적용 대상
Block(Expression[])
- Source:
- BlockExpression.cs
- Source:
- BlockExpression.cs
- Source:
- BlockExpression.cs
지정된 식을 포함하고 변수가 없는 BlockExpression을 만듭니다.
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
매개 변수
- expressions
- Expression[]
블록의 식입니다.
반환
만든 BlockExpression입니다.
예제
다음 코드 예제에서는 블록 식을 만드는 방법을 보여줍니다. 블록 식은 두 MethodCallExpression 개의 개체와 하나의 ConstantExpression 개체로 구성됩니다.
// 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
설명
블록 식이 실행되면 블록의 마지막 식 값을 반환합니다.
적용 대상
Block(IEnumerable<Expression>)
- Source:
- BlockExpression.cs
- Source:
- BlockExpression.cs
- Source:
- BlockExpression.cs
지정된 식을 포함하고 변수가 없는 BlockExpression을 만듭니다.
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
매개 변수
- expressions
- IEnumerable<Expression>
블록의 식입니다.
반환
만든 BlockExpression입니다.
설명
블록 식이 실행되면 블록의 마지막 식 값을 반환합니다.
적용 대상
Block(Type, IEnumerable<Expression>)
- Source:
- BlockExpression.cs
- Source:
- BlockExpression.cs
- Source:
- BlockExpression.cs
지정된 식을 포함하고 변수가 없으며 특정 결과 형식이 있는 BlockExpression을 만듭니다.
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
매개 변수
- type
- Type
블록의 결과 형식입니다.
- expressions
- IEnumerable<Expression>
블록의 식입니다.
반환
만든 BlockExpression입니다.
적용 대상
.NET