Expression.NewArrayInit Method (Type, IEnumerable<Expression>)

 

Creates a NewArrayExpression that represents creating a one-dimensional array and initializing it from a list of elements.

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

static member NewArrayInit : 
        type:Type *
        initializers:IEnumerable<Expression> -> NewArrayExpression

Parameters

type
Type: System.Type

A Type that represents the element type of the array.

initializers
Type: System.Collections.Generic.IEnumerable<Expression>

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

Return Value

Type: System.Linq.Expressions.NewArrayExpression

A NewArrayExpression that has the NodeType property equal to NewArrayInit and the Expressions property set to the specified value.

Exception Condition
ArgumentNullException

type or initializers is null.

-or-

An element of initializers is null.

InvalidOperationException

The Type property of an element of initializers represents a type that is not assignable to the type that type represents.

The Type property of each element of initializers must represent a type that is assignable to the type represented by type, possibly after it is quoted.

System_CAPS_noteNote

An element will be quoted only if type is Expression. Quoting means the element is wrapped in a Quote node. The resulting node is a UnaryExpression whose Operand property is the element of initializers.

The Type property of the resulting NewArrayExpression represents an array type whose rank is 1 and whose element type is type.

The following example demonstrates how to use the NewArrayInit method to create an expression tree that represents creating a one-dimensional string array that is initialized with a list of string expressions.

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 8
.NET Framework
Available since 3.5
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show: