Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Expression::ListInit Method (NewExpression^, array<ElementInit^>^)

 

Creates a ListInitExpression that uses specified ElementInit objects to initialize a collection.

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

public:
static ListInitExpression^ ListInit(
	NewExpression^ newExpression,
	... array<ElementInit^>^ initializers
)

Parameters

newExpression
Type: System.Linq.Expressions::NewExpression^

A NewExpression to set the NewExpression property equal to.

initializers
Type: array<System.Linq.Expressions::ElementInit^>^

An array of ElementInit objects to use to populate the Initializers collection.

Return Value

Type: System.Linq.Expressions::ListInitExpression^

A ListInitExpression that has the NodeType property equal to ListInit and the NewExpression and Initializers properties set to the specified values.

Exception Condition
ArgumentNullException

newExpression or initializers is null.

-or-

One or more elements of initializers are null.

ArgumentException

newExpression.Type does not implement IEnumerable.

The Type property of newExpression must represent a type that implements IEnumerable.

The Type property of the resulting ListInitExpression is equal to newExpression.Type.

The following example demonstrates how to use the ListInit(NewExpression^, array<ElementInit^>^) method to create a ListInitExpressionthat represents the initialization of a new dictionary instance with two key-value pairs.

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:
© 2017 Microsoft