Expression.ArrayIndex 方法

定義

建立 Expression,表示套用陣列索引運算子。

多載

ArrayIndex(Expression, Expression[])

建立 MethodCallExpression,代表將陣列索引運算子套用到多維陣列。

ArrayIndex(Expression, IEnumerable<Expression>)

建立 MethodCallExpression,代表將陣列索引運算子套用到陣序規範大於 1 的陣列。

ArrayIndex(Expression, Expression)

建立 BinaryExpression,代表將陣列索引運算子套用到陣序規範 1 的陣列。

ArrayIndex(Expression, Expression[])

建立 MethodCallExpression,代表將陣列索引運算子套用到多維陣列。

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 執行個體 (用於陣列索引運算的索引) 的陣列。

indexes
Expression[]

用以填入 Expression 集合之 Arguments 物件的陣列。

傳回

MethodCallExpression

MethodCallExpression,其 NodeType 屬性等於 Call,且 ObjectArguments 屬性設定為指定的值。

例外狀況

arrayindexesnull

array.Type 不代表陣列類型。

-或- array.Type 的陣序規範不符合 indexes 中的項目數。

-或- indexes 之一個或多個項目的 Type 屬性不代表 Int32 類型。

範例

下列範例示範如何使用 ArrayIndex(Expression, Expression[]) 方法來建立 , MethodCallExpression 表示索引編制至二維陣列。

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 等於 Int32 。 的 Type array 屬性必須代表符合 中 indexes 專案數目的陣列類型。

如果 的排名為 array 。類型為 1,這個方法會傳 BinaryExpression 回 。 屬性 Left 設定為 array ,而 Right 屬性會設定為 的單 indexes 一元素。 TypeBinaryExpression 屬性代表 的專案 array 類型。類型。

如果 的排名為 array 。類型為一個以上,這個方法會傳 MethodCallExpression 回 。 屬性 Method 會設定為 , MethodInfo 描述 屬性所 Type array 表示之型別上的公用實例方法 Get

適用於

ArrayIndex(Expression, IEnumerable<Expression>)

建立 MethodCallExpression,代表將陣列索引運算子套用到陣序規範大於 1 的陣列。

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 屬性設定為與之相等的 Object

indexes
IEnumerable<Expression>

IEnumerable<T>,其中包含用以填入 Expression 集合的 Arguments 物件。

傳回

MethodCallExpression

MethodCallExpression,其 NodeType 屬性等於 Call,且 ObjectArguments 屬性設定為指定的值。

例外狀況

arrayindexesnull

array.Type 不代表陣列類型。

-或- array.Type 的陣序規範不符合 indexes 中的項目數。

-或- indexes 之一個或多個項目的 Type 屬性不代表 Int32 類型。

範例

下列範例示範如何使用 ArrayIndex(Expression, Expression[]) 方法來建立 , MethodCallExpression 表示索引編制至二維陣列。

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 等於 Int32 。 的 Type array 屬性必須代表符合 中 indexes 專案數目的陣列類型。

如果 的排名為 array 。類型為 1,這個方法會傳 BinaryExpression 回 。 屬性 Left 設定為 array ,而 Right 屬性會設定為 的單 indexes 一元素。 TypeBinaryExpression 屬性代表 的專案 array 類型。類型。

如果 的排名為 array 。類型為一個以上,這個方法會傳 MethodCallExpression 回 。 屬性 Method 會設定為 , MethodInfo 描述 屬性所 Type array 表示之型別上的公用實例方法 Get

適用於

ArrayIndex(Expression, Expression)

建立 BinaryExpression,代表將陣列索引運算子套用到陣序規範 1 的陣列。

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 屬性設定為與之相等的 Left

index
Expression

要將 Expression 屬性設定為與之相等的 Right

傳回

BinaryExpression

BinaryExpression,其 NodeType 屬性等於 ArrayIndex,且 LeftRight 屬性設定為指定的值。

例外狀況

arrayindexnull

array.Type 不代表陣列類型。

-或- array.Type 代表其陣序規範不為 1 的陣列類型。

-或- index.Type 不代表 Int32 類型。

備註

index 必須代表 型 Int32 別的索引。

Method產生的 BinaryExpression 屬性為 null ,且 和 IsLiftedToNullIsLifted 設定為 false 。 屬性 Type 等於 的專案 array 類型。類型。 Conversion 屬性為 null

適用於