Freigeben über


Expression.NewArrayBounds Method (Type, array<Expression[])

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Creates a NewArrayExpression that represents creating an array that has a specified rank.

Namespace:  System.Linq.Expressions
Assembly:  System.Core (in System.Core.dll)

Syntax

'Declaration
Public Shared Function NewArrayBounds ( _
    type As Type, _
    ParamArray bounds As Expression() _
) As NewArrayExpression
public static NewArrayExpression NewArrayBounds(
    Type type,
    params Expression[] bounds
)

Parameters

  • type
    Type: System.Type
    A Type that represents the element type of the array.

Return Value

Type: System.Linq.Expressions.NewArrayExpression
A NewArrayExpression that has the NodeType property equal to NewArrayBounds and the Expressions property set to the specified value.

Exceptions

Exception Condition
ArgumentNullException

type or bounds is nulla null reference (Nothing in Visual Basic).

-or-

An element of bounds is nulla null reference (Nothing in Visual Basic).

ArgumentException

The Type property of an element of bounds does not represent an integral type.

Remarks

The Type property of the resulting NewArrayExpression represents an array type whose rank is equal to the length of bounds and whose element type is type.

The Type property of each element of bounds must represent an integral type.

Examples

The following example demonstrates how to use the NewArrayBounds method to create an expression tree that represents creating a string array that has a rank of 2.

' Create an expression tree that represents creating a string
' array with rank 2 and bounds (3,2).
Dim newArrayExpression As System.Linq.Expressions.NewArrayExpression = _
    System.Linq.Expressions.Expression.NewArrayBounds( _
            Type.GetType("System.String"), _
            System.Linq.Expressions.Expression.Constant(3), _
            System.Linq.Expressions.Expression.Constant(2))

' Output the string representation of the Expression.
outputBlock.Text &= newArrayExpression.ToString() & vbCrLf

' This code produces the following output:
'
' new System.String[,](3, 2)
// Create an expression tree that represents creating a 
// two-dimensional array of type string with bounds [3,2].
System.Linq.Expressions.NewArrayExpression newArrayExpression =
    System.Linq.Expressions.Expression.NewArrayBounds(
            typeof(string),
            System.Linq.Expressions.Expression.Constant(3),
            System.Linq.Expressions.Expression.Constant(2));

// Output the string representation of the Expression.
outputBlock.Text += newArrayExpression.ToString() + "\n";

// This code produces the following output:
//
// new System.String[,](3, 2)

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.