Expression.ArrayAccess 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
배열에 액세스할 IndexExpression을 만듭니다.
오버로드
ArrayAccess(Expression, IEnumerable<Expression>) |
다차원 배열에 액세스할 IndexExpression을 만듭니다. |
ArrayAccess(Expression, Expression[]) |
배열에 액세스할 IndexExpression을 만듭니다. |
ArrayAccess(Expression, IEnumerable<Expression>)
- Source:
- IndexExpression.cs
- Source:
- IndexExpression.cs
- Source:
- IndexExpression.cs
다차원 배열에 액세스할 IndexExpression을 만듭니다.
public:
static System::Linq::Expressions::IndexExpression ^ ArrayAccess(System::Linq::Expressions::Expression ^ array, System::Collections::Generic::IEnumerable<System::Linq::Expressions::Expression ^> ^ indexes);
public static System.Linq.Expressions.IndexExpression ArrayAccess (System.Linq.Expressions.Expression array, System.Collections.Generic.IEnumerable<System.Linq.Expressions.Expression> indexes);
public static System.Linq.Expressions.IndexExpression ArrayAccess (System.Linq.Expressions.Expression array, System.Collections.Generic.IEnumerable<System.Linq.Expressions.Expression>? indexes);
static member ArrayAccess : System.Linq.Expressions.Expression * seq<System.Linq.Expressions.Expression> -> System.Linq.Expressions.IndexExpression
Public Shared Function ArrayAccess (array As Expression, indexes As IEnumerable(Of Expression)) As IndexExpression
매개 변수
- array
- Expression
다차원 배열을 나타내는 식입니다.
- indexes
- IEnumerable<Expression>
배열을 인덱싱하는 데 사용되는 식이 포함된 IEnumerable<T>입니다.
반환
만든 IndexExpression입니다.
예제
다음 코드 예제에서는 메서드를 사용 하 여 다차원 배열에서 요소의 값을 변경 하는 ArrayAccess
방법을 보여 줍니다.
// Add the following directive to your file:
// using System.Linq.Expressions;
// This parameter expression represents a variable that will hold the two-dimensional array.
ParameterExpression arrayExpr = Expression.Parameter(typeof(int[,]), "Array");
// This parameter expression represents a first array index.
ParameterExpression firstIndexExpr = Expression.Parameter(typeof(int), "FirstIndex");
// This parameter expression represents a second array index.
ParameterExpression secondIndexExpr = Expression.Parameter(typeof(int), "SecondIndex");
// The list of indexes.
List<Expression> indexes = new List<Expression> { firstIndexExpr, secondIndexExpr };
// This parameter represents the value that will be added to a corresponding array element.
ParameterExpression valueExpr = Expression.Parameter(typeof(int), "Value");
// This expression represents an access operation to a multidimensional array.
// It can be used for assigning to, or reading from, an array element.
Expression arrayAccessExpr = Expression.ArrayAccess(
arrayExpr,
indexes
);
// This lambda expression assigns a value provided to it to a specified array element.
// The array, the index of the array element, and the value to be added to the element
// are parameters of the lambda expression.
Expression<Func<int[,], int, int, int, int>> lambdaExpr =
Expression.Lambda<Func<int[,], int, int, int, int>>(
Expression.Assign(arrayAccessExpr, Expression.Add(arrayAccessExpr, valueExpr)),
arrayExpr,
firstIndexExpr,
secondIndexExpr,
valueExpr
);
// Print out expressions.
Console.WriteLine("Array Access Expression:");
Console.WriteLine(arrayAccessExpr.ToString());
Console.WriteLine("Lambda Expression:");
Console.WriteLine(lambdaExpr.ToString());
Console.WriteLine("The result of executing the lambda expression:");
// The following statement first creates an expression tree,
// then compiles it, and then executes it.
// Parameters passed to the Invoke method are passed to the lambda expression.
int[,] sampleArray = { {10, 20, 30},
{100, 200, 300}};
Console.WriteLine(lambdaExpr.Compile().Invoke(sampleArray, 1, 1, 5));
// This code example produces the following output:
//
// Array Access Expression:
// Array[FirstIndex, SecondIndex]
// Lambda Expression:
// (Array, FirstIndex, SecondIndex Value) =>
// (Array[FirstIndex, SecondIndex] = (Array[FirstIndex, SecondIndex] + Value))
// The result of executing the lambda expression:
// 205
' Add the following directive to your file:
' Imports System.Linq.Expressions
' This parameter expression represents a variable that will hold the two-dimensional array.
Dim arrayExpr As ParameterExpression = Expression.Parameter(GetType(Integer(,)), "Array")
' This parameter expression represents a first array index.
Dim firstIndexExpr As ParameterExpression = Expression.Parameter(GetType(Integer), "FirstIndex")
' This parameter expression represents a second array index.
Dim secondIndexExpr As ParameterExpression = Expression.Parameter(GetType(Integer), "SecondIndex")
' The list of indexes.
Dim indexes As List(Of Expression) = New List(Of Expression) From
{firstIndexExpr, secondIndexExpr}
' This parameter represents the value that will be added to a corresponding array element.
Dim valueExpr As ParameterExpression = Expression.Parameter(GetType(Integer), "Value")
' This expression represents an access operation to a multidimensional array.
' It can be used for assigning to, or reading from, an array element.
Dim arrayAccessExpr As Expression = Expression.ArrayAccess(
arrayExpr,
indexes
)
' This lambda expression assigns a value provided to it to a specified array element.
' The array, the index of the array element, and the value to be added to the element
' are parameters of the lambda expression.
Dim lambdaExpr As Expression(Of Func(Of Integer(,), Integer, Integer, Integer, Integer)) =
Expression.Lambda(Of Func(Of Integer(,), Integer, Integer, Integer, Integer))(
Expression.Assign(arrayAccessExpr, Expression.Add(arrayAccessExpr, valueExpr)),
arrayExpr,
firstIndexExpr,
secondIndexExpr,
valueExpr
)
' Print expressions.
Console.WriteLine("Array Access Expression:")
Console.WriteLine(arrayAccessExpr.ToString())
Console.WriteLine("Lambda Expression:")
Console.WriteLine(lambdaExpr.ToString())
Console.WriteLine("The result of executing the lambda expression:")
' The following statement first creates an expression tree,
' then compiles it, and then executes it.
' Parameters passed to the Invoke method are passed to the lambda expression.
Dim sampleArray = {{10, 20, 30},
{100, 200, 300}}
Console.WriteLine(lambdaExpr.Compile().Invoke(sampleArray, 1, 1, 5))
' This code example produces the following output:
'
' Array Access Expression:
' Array[FirstIndex, SecondIndex]
' Lambda Expression:
' (Array, FirstIndex, SecondIndex Value) =>
' (Array[FirstIndex, SecondIndex] = (Array[FirstIndex, SecondIndex] + Value))
' The result of executing the lambda expression:
' 205
설명
배열을 나타내는 식은 메서드를 사용하거나 또는 NewArrayInit을 MakeMemberAccess 통해 NewArrayBounds 가져올 수 있습니다.
적용 대상
ArrayAccess(Expression, Expression[])
- Source:
- IndexExpression.cs
- Source:
- IndexExpression.cs
- Source:
- IndexExpression.cs
배열에 액세스할 IndexExpression을 만듭니다.
public:
static System::Linq::Expressions::IndexExpression ^ ArrayAccess(System::Linq::Expressions::Expression ^ array, ... cli::array <System::Linq::Expressions::Expression ^> ^ indexes);
public static System.Linq.Expressions.IndexExpression ArrayAccess (System.Linq.Expressions.Expression array, params System.Linq.Expressions.Expression[] indexes);
public static System.Linq.Expressions.IndexExpression ArrayAccess (System.Linq.Expressions.Expression array, params System.Linq.Expressions.Expression[]? indexes);
static member ArrayAccess : System.Linq.Expressions.Expression * System.Linq.Expressions.Expression[] -> System.Linq.Expressions.IndexExpression
Public Shared Function ArrayAccess (array As Expression, ParamArray indexes As Expression()) As IndexExpression
매개 변수
- array
- Expression
인덱싱할 배열을 나타내는 식입니다.
- indexes
- Expression[]
배열을 인덱싱하는 데 사용되는 식이 포함된 배열입니다.
반환
만든 IndexExpression입니다.
예제
다음 코드 예제를 사용 하 여 배열 요소의 값을 변경 하는 방법을 보여 주는 ArrayAccess
메서드입니다.
// Add the following directive to your file:
// using System.Linq.Expressions;
// This parameter expression represents a variable that will hold the array.
ParameterExpression arrayExpr = Expression.Parameter(typeof(int[]), "Array");
// This parameter expression represents an array index.
ParameterExpression indexExpr = Expression.Parameter(typeof(int), "Index");
// This parameter represents the value that will be added to a corresponding array element.
ParameterExpression valueExpr = Expression.Parameter(typeof(int), "Value");
// This expression represents an array access operation.
// It can be used for assigning to, or reading from, an array element.
Expression arrayAccessExpr = Expression.ArrayAccess(
arrayExpr,
indexExpr
);
// This lambda expression assigns a value provided to it to a specified array element.
// The array, the index of the array element, and the value to be added to the element
// are parameters of the lambda expression.
Expression<Func<int[], int, int, int>> lambdaExpr = Expression.Lambda<Func<int[], int, int, int>>(
Expression.Assign(arrayAccessExpr, Expression.Add(arrayAccessExpr, valueExpr)),
arrayExpr,
indexExpr,
valueExpr
);
// Print out expressions.
Console.WriteLine("Array Access Expression:");
Console.WriteLine(arrayAccessExpr.ToString());
Console.WriteLine("Lambda Expression:");
Console.WriteLine(lambdaExpr.ToString());
Console.WriteLine("The result of executing the lambda expression:");
// The following statement first creates an expression tree,
// then compiles it, and then executes it.
// Parameters passed to the Invoke method are passed to the lambda expression.
Console.WriteLine(lambdaExpr.Compile().Invoke(new int[] { 10, 20, 30 }, 0, 5));
// This code example produces the following output:
//
// Array Access Expression:
// Array[Index]
// Lambda Expression:
// (Array, Index, Value) => (Array[Index] = (Array[Index] + Value))
// The result of executing the lambda expression:
// 15
' Add the following directive to your file:
' Imports System.Linq.Expressions
' This parameter expression represents a variable that will hold the array.
Dim arrayExpr As ParameterExpression = Expression.Parameter(GetType(Integer()), "Array")
' This parameter expression represents an array index.
' For multidimensional arrays, you can define several indexes.
Dim indexExpr As ParameterExpression = Expression.Parameter(GetType(Integer), "Index")
' This parameter represents the value that will be added to a corresponding array element.
Dim valueExpr As ParameterExpression = Expression.Parameter(GetType(Integer), "Value")
' This expression represents an array access operation.
' It can be used for assigning to, or reading from, an array element.
Dim arrayAccessExpr As Expression = Expression.ArrayAccess(
arrayExpr,
indexExpr
)
' This lambda expression assigns a value provided to it to a specified array element.
' The array, the index of the array element, and the value to be added to the element
' are parameters of the lambda expression.
Dim lambdaExpr As Expression(Of Func(Of Integer(), Integer, Integer, Integer)) =
Expression.Lambda(Of Func(Of Integer(), Integer, Integer, Integer))(
Expression.Assign(arrayAccessExpr, Expression.Add(arrayAccessExpr, valueExpr)),
arrayExpr,
indexExpr,
valueExpr
)
' Print expressions.
Console.WriteLine("Array Access Expression:")
Console.WriteLine(arrayAccessExpr.ToString())
Console.WriteLine("Lambda Expression:")
Console.WriteLine(lambdaExpr.ToString())
Console.WriteLine("The result of executing the lambda expression:")
' The following statement first creates an expression tree,
' then compiles it, and then executes it.
' Parameters passed to the Invoke method are passed to the lambda expression.
Console.WriteLine(lambdaExpr.Compile().Invoke(New Integer() {10, 20, 30}, 0, 5))
' This code example produces the following output:
'
' Array Access Expression:
' Array[Index]
' Lambda Expression:
' (Array, Index, Value) => (Array[Index] = (Array[Index] + Value))
' The result of executing the lambda expression:
' 15
설명
배열을 나타내는 식은 메서드를 사용하거나 또는 NewArrayInit을 MakeMemberAccess 통해 NewArrayBounds 가져올 수 있습니다.
다차원 배열의 경우 메서드를 ArrayAccess 사용합니다.
적용 대상
.NET