संपादित करें

इसके माध्यम से साझा किया गया


Expression.ArrayIndex Method

Definition

Creates an Expression that represents applying an array index operator.

Overloads

ArrayIndex(Expression, Expression[])

Creates a MethodCallExpression that represents applying an array index operator to a multidimensional array.

ArrayIndex(Expression, IEnumerable<Expression>)

Creates a MethodCallExpression that represents applying an array index operator to an array of rank more than one.

ArrayIndex(Expression, Expression)

Creates a BinaryExpression that represents applying an array index operator to an array of rank one.

ArrayIndex(Expression, Expression[])

Source:
MethodCallExpression.cs
Source:
MethodCallExpression.cs
Source:
MethodCallExpression.cs

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

Parameters

array
Expression

An array of Expression instances - indexes for the array index operation.

indexes
Expression[]

An array of Expression objects to use to populate the Arguments collection.

Returns

A MethodCallExpression that has the NodeType property equal to Call and the Object and Arguments properties set to the specified values.

Exceptions

array or indexes is null.

array.Type does not represent an array type.

-or-

The rank of array.Type does not match the number of elements in indexes.

-or-

The Type property of one or more elements of indexes does not represent the Int32 type.

Examples

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)

Remarks

Each element of indexes must have Type equal to Int32. The Type property of array must represent an array type whose rank matches the number of elements in indexes.

If the rank of array.Type is 1, this method returns a BinaryExpression. The Left property is set to array and the Right property is set to the single element of indexes. The Type property of the BinaryExpression represents the element type of array.Type.

If the rank of array.Type is more than one, this method returns a MethodCallExpression. The Method property is set to the MethodInfo that describes the public instance method Get on the type represented by the Type property of array.

Applies to

ArrayIndex(Expression, IEnumerable<Expression>)

Source:
MethodCallExpression.cs
Source:
MethodCallExpression.cs
Source:
MethodCallExpression.cs

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

Parameters

array
Expression

An Expression to set the Object property equal to.

indexes
IEnumerable<Expression>

An IEnumerable<T> that contains Expression objects to use to populate the Arguments collection.

Returns

A MethodCallExpression that has the NodeType property equal to Call and the Object and Arguments properties set to the specified values.

Exceptions

array or indexes is null.

array.Type does not represent an array type.

-or-

The rank of array.Type does not match the number of elements in indexes.

-or-

The Type property of one or more elements of indexes does not represent the Int32 type.

Examples

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)

Remarks

Each element of indexes must have Type equal to Int32. The Type property of array must represent an array type whose rank matches the number of elements in indexes.

If the rank of array.Type is 1, this method returns a BinaryExpression. The Left property is set to array and the Right property is set to the single element of indexes. The Type property of the BinaryExpression represents the element type of array.Type.

If the rank of array.Type is more than one, this method returns a MethodCallExpression. The Method property is set to the MethodInfo that describes the public instance method Get on the type represented by the Type property of array.

Applies to

ArrayIndex(Expression, Expression)

Source:
BinaryExpression.cs
Source:
BinaryExpression.cs
Source:
BinaryExpression.cs

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

Parameters

array
Expression

A Expression to set the Left property equal to.

index
Expression

A Expression to set the Right property equal to.

Returns

A BinaryExpression that has the NodeType property equal to ArrayIndex and the Left and Right properties set to the specified values.

Exceptions

array or index is null.

array.Type does not represent an array type.

-or-

array.Type represents an array type whose rank is not 1.

-or-

index.Type does not represent the Int32 type.

Remarks

index must represent an index of type Int32.

The Method property of the resulting BinaryExpression is null, and both IsLifted and IsLiftedToNull are set to false. The Type property is equal to the element type of array.Type. The Conversion property is null.

Applies to