Expression.ArrayIndex 方法

定義

建立 Expression,表示套用陣列索引運算子。Creates an Expression that represents applying an array index operator.

多載

ArrayIndex(Expression, Expression[])

建立 MethodCallExpression,代表將陣列索引運算子套用到多維陣列。Creates a MethodCallExpression that represents applying an array index operator to a multidimensional array.

ArrayIndex(Expression, IEnumerable<Expression>)

建立 MethodCallExpression,代表將陣列索引運算子套用到陣序規範大於 1 的陣列。Creates a MethodCallExpression that represents applying an array index operator to an array of rank more than one.

ArrayIndex(Expression, Expression)

建立 BinaryExpression,代表將陣列索引運算子套用到陣序規範 1 的陣列。Creates a BinaryExpression that represents applying an array index operator to an array of rank one.

ArrayIndex(Expression, Expression[])

建立 MethodCallExpression,代表將陣列索引運算子套用到多維陣列。Creates a MethodCallExpression that represents applying an array index operator to a multidimensional array.

public:
 static System::Linq::Expressions::MethodCallExpression ^ ArrayIndex(System::Linq::Expressions::Expression ^ array, ... cli::array <System::Linq::Expressions::Expression ^> ^ indexes);
public static System.Linq.Expressions.MethodCallExpression ArrayIndex (System.Linq.Expressions.Expression array, params System.Linq.Expressions.Expression[] indexes);
static member ArrayIndex : System.Linq.Expressions.Expression * System.Linq.Expressions.Expression[] -> System.Linq.Expressions.MethodCallExpression
Public Shared Function ArrayIndex (array As Expression, ParamArray indexes As Expression()) As MethodCallExpression

參數

array
Expression

Expression 執行個體 (用於陣列索引運算的索引) 的陣列。An array of Expression instances - indexes for the array index operation.

indexes
Expression[]

用以填入 Expression 集合之 Arguments 物件的陣列。An array of Expression objects to use to populate the Arguments collection.

傳回

MethodCallExpression

MethodCallExpression,其 NodeType 屬性等於 Call,且 ObjectArguments 屬性設定為指定的值。A MethodCallExpression that has the NodeType property equal to Call and the Object and Arguments properties set to the specified values.

例外狀況

arrayindexesnullarray or indexes is null.

array.Type 不代表陣列類型。array.Type does not represent an array type.

-或--or- array.Type 的陣序規範不符合 indexes 中的項目數。The rank of array.Type does not match the number of elements in indexes.

-或--or- indexes 之一個或多個項目的 Type 屬性不代表 Int32 類型。The Type property of one or more elements of indexes does not represent the Int32 type.

範例

下列範例示範如何使用 ArrayIndex(Expression, Expression[]) 方法來建立,其代表在 MethodCallExpression 二維陣列中編制索引。The following example demonstrates how to use the ArrayIndex(Expression, Expression[]) method to create a MethodCallExpression that represents indexing into a two-dimensional array.

string[,] gradeArray =
    { {"chemistry", "history", "mathematics"}, {"78", "61", "82"} };

System.Linq.Expressions.Expression arrayExpression =
    System.Linq.Expressions.Expression.Constant(gradeArray);

// Create a MethodCallExpression that represents indexing
// into the two-dimensional array 'gradeArray' at (0, 2).
// Executing the expression would return "mathematics".
System.Linq.Expressions.MethodCallExpression methodCallExpression =
    System.Linq.Expressions.Expression.ArrayIndex(
        arrayExpression,
        System.Linq.Expressions.Expression.Constant(0),
        System.Linq.Expressions.Expression.Constant(2));

Console.WriteLine(methodCallExpression.ToString());

// This code produces the following output:
//
// value(System.String[,]).Get(0, 2)
Dim gradeArray(,) As String = _
    {{"chemistry", "history", "mathematics"}, {"78", "61", "82"}}

Dim arrayExpression As System.Linq.Expressions.Expression = _
    System.Linq.Expressions.Expression.Constant(gradeArray)

' Create a MethodCallExpression that represents indexing
' into the two-dimensional array 'gradeArray' at (0, 2).
' Executing the expression would return "mathematics".
Dim methodCallExpression As System.Linq.Expressions.MethodCallExpression = _
    System.Linq.Expressions.Expression.ArrayIndex( _
        arrayExpression, _
        System.Linq.Expressions.Expression.Constant(0), _
        System.Linq.Expressions.Expression.Constant(2))

Console.WriteLine(methodCallExpression.ToString())

' This code produces the following output:
'
' value(System.String[,]).Get(0, 2)

備註

的每個元素都 indexes 必須 Type 等於 Int32Each element of indexes must have Type equal to Int32. Type 屬性 array 必須代表陣列型別,其排名符合中的元素數 indexesThe Type property of array must represent an array type whose rank matches the number of elements in indexes.

如果的順位 array 。類型為1,這個方法會傳回 BinaryExpressionIf the rank of array.Type is 1, this method returns a BinaryExpression. Left屬性設定為 array ,且 Right 屬性設定為的單一元素 indexesThe Left property is set to array and the Right property is set to the single element of indexes. Type 屬性代表的 BinaryExpression 元素類型 array 。類型。The Type property of the BinaryExpression represents the element type of array.Type.

如果的順位 array 。類型是一個以上,這個方法會傳回 MethodCallExpressionIf the rank of array.Type is more than one, this method returns a MethodCallExpression. Method屬性(property)會設定為 MethodInfo ,它會在的 Get Type 屬性(property)所表示的型別上描述公用實例方法 arrayThe Method property is set to the MethodInfo that describes the public instance method Get on the type represented by the Type property of array.

適用於

ArrayIndex(Expression, IEnumerable<Expression>)

建立 MethodCallExpression,代表將陣列索引運算子套用到陣序規範大於 1 的陣列。Creates a MethodCallExpression that represents applying an array index operator to an array of rank more than one.

public:
 static System::Linq::Expressions::MethodCallExpression ^ ArrayIndex(System::Linq::Expressions::Expression ^ array, System::Collections::Generic::IEnumerable<System::Linq::Expressions::Expression ^> ^ indexes);
public static System.Linq.Expressions.MethodCallExpression ArrayIndex (System.Linq.Expressions.Expression array, System.Collections.Generic.IEnumerable<System.Linq.Expressions.Expression> indexes);
static member ArrayIndex : System.Linq.Expressions.Expression * seq<System.Linq.Expressions.Expression> -> System.Linq.Expressions.MethodCallExpression
Public Shared Function ArrayIndex (array As Expression, indexes As IEnumerable(Of Expression)) As MethodCallExpression

參數

array
Expression

要將 Expression 屬性設定為與之相等的 ObjectAn Expression to set the Object property equal to.

indexes
IEnumerable<Expression>

IEnumerable<T>,其中包含用以填入 Expression 集合的 Arguments 物件。An IEnumerable<T> that contains Expression objects to use to populate the Arguments collection.

傳回

MethodCallExpression

MethodCallExpression,其 NodeType 屬性等於 Call,且 ObjectArguments 屬性設定為指定的值。A MethodCallExpression that has the NodeType property equal to Call and the Object and Arguments properties set to the specified values.

例外狀況

arrayindexesnullarray or indexes is null.

array.Type 不代表陣列類型。array.Type does not represent an array type.

-或--or- array.Type 的陣序規範不符合 indexes 中的項目數。The rank of array.Type does not match the number of elements in indexes.

-或--or- indexes 之一個或多個項目的 Type 屬性不代表 Int32 類型。The Type property of one or more elements of indexes does not represent the Int32 type.

範例

下列範例示範如何使用 ArrayIndex(Expression, Expression[]) 方法來建立,其代表在 MethodCallExpression 二維陣列中編制索引。The following example demonstrates how to use the ArrayIndex(Expression, Expression[]) method to create a MethodCallExpression that represents indexing into a two-dimensional array.

string[,] gradeArray =
    { {"chemistry", "history", "mathematics"}, {"78", "61", "82"} };

System.Linq.Expressions.Expression arrayExpression =
    System.Linq.Expressions.Expression.Constant(gradeArray);

// Create a MethodCallExpression that represents indexing
// into the two-dimensional array 'gradeArray' at (0, 2).
// Executing the expression would return "mathematics".
System.Linq.Expressions.MethodCallExpression methodCallExpression =
    System.Linq.Expressions.Expression.ArrayIndex(
        arrayExpression,
        System.Linq.Expressions.Expression.Constant(0),
        System.Linq.Expressions.Expression.Constant(2));

Console.WriteLine(methodCallExpression.ToString());

// This code produces the following output:
//
// value(System.String[,]).Get(0, 2)
Dim gradeArray(,) As String = _
    {{"chemistry", "history", "mathematics"}, {"78", "61", "82"}}

Dim arrayExpression As System.Linq.Expressions.Expression = _
    System.Linq.Expressions.Expression.Constant(gradeArray)

' Create a MethodCallExpression that represents indexing
' into the two-dimensional array 'gradeArray' at (0, 2).
' Executing the expression would return "mathematics".
Dim methodCallExpression As System.Linq.Expressions.MethodCallExpression = _
    System.Linq.Expressions.Expression.ArrayIndex( _
        arrayExpression, _
        System.Linq.Expressions.Expression.Constant(0), _
        System.Linq.Expressions.Expression.Constant(2))

Console.WriteLine(methodCallExpression.ToString())

' This code produces the following output:
'
' value(System.String[,]).Get(0, 2)

備註

的每個元素都 indexes 必須 Type 等於 Int32Each element of indexes must have Type equal to Int32. Type 屬性 array 必須代表陣列型別,其排名符合中的元素數 indexesThe Type property of array must represent an array type whose rank matches the number of elements in indexes.

如果的順位 array 。類型為1,這個方法會傳回 BinaryExpressionIf the rank of array.Type is 1, this method returns a BinaryExpression. Left屬性設定為 array ,且 Right 屬性設定為的單一元素 indexesThe Left property is set to array and the Right property is set to the single element of indexes. Type 屬性代表的 BinaryExpression 元素類型 array 。類型。The Type property of the BinaryExpression represents the element type of array.Type.

如果的順位 array 。類型是一個以上,這個方法會傳回 MethodCallExpressionIf the rank of array.Type is more than one, this method returns a MethodCallExpression. Method屬性(property)會設定為 MethodInfo ,它會在的 Get Type 屬性(property)所表示的型別上描述公用實例方法 arrayThe Method property is set to the MethodInfo that describes the public instance method Get on the type represented by the Type property of array.

適用於

ArrayIndex(Expression, Expression)

建立 BinaryExpression,代表將陣列索引運算子套用到陣序規範 1 的陣列。Creates a BinaryExpression that represents applying an array index operator to an array of rank one.

public:
 static System::Linq::Expressions::BinaryExpression ^ ArrayIndex(System::Linq::Expressions::Expression ^ array, System::Linq::Expressions::Expression ^ index);
public static System.Linq.Expressions.BinaryExpression ArrayIndex (System.Linq.Expressions.Expression array, System.Linq.Expressions.Expression index);
static member ArrayIndex : System.Linq.Expressions.Expression * System.Linq.Expressions.Expression -> System.Linq.Expressions.BinaryExpression
Public Shared Function ArrayIndex (array As Expression, index As Expression) As BinaryExpression

參數

array
Expression

要將 Expression 屬性設定為與之相等的 LeftA Expression to set the Left property equal to.

index
Expression

要將 Expression 屬性設定為與之相等的 RightA Expression to set the Right property equal to.

傳回

BinaryExpression

BinaryExpression,其 NodeType 屬性等於 ArrayIndex,且 LeftRight 屬性設定為指定的值。A BinaryExpression that has the NodeType property equal to ArrayIndex and the Left and Right properties set to the specified values.

例外狀況

arrayindexnullarray or index is null.

array.Type 不代表陣列類型。array.Type does not represent an array type.

-或--or- array.Type 代表其陣序規範不為 1 的陣列類型。array.Type represents an array type whose rank is not 1.

-或--or- index.Type 不代表 Int32 類型。index.Type does not represent the Int32 type.

備註

index 必須代表類型的索引 Int32index must represent an index of type Int32.

Method產生的屬性 BinaryExpressionnull ,而且 IsLifted 和都 IsLiftedToNull 設定為 falseThe Method property of the resulting BinaryExpression is null, and both IsLifted and IsLiftedToNull are set to false. Type屬性等於的元素類型 array 。類型。The Type property is equal to the element type of array.Type. Conversion 屬性為 nullThe Conversion property is null.

適用於