Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Expression.ListInit Method (NewExpression, ElementInit[])

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

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

static member ListInit : 
        newExpression:NewExpression * 
        initializers:ElementInit[] -> ListInitExpression


Type: System.Linq.Expressions.NewExpression

A NewExpression to set the NewExpression property equal to.

Type: 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.


newExpression or initializers is a null reference (Nothing in Visual Basic).


One or more elements of initializers are a null reference (Nothing in Visual Basic).


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, ElementInit[]) method to create a ListInitExpression that 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.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Portable Class Library

Supported in: Portable Class Library
© 2015 Microsoft