Expression.ListInit Method (NewExpression, Expression())
Creates a ListInitExpression that uses a method named "Add" to add elements to a collection.
Assembly: System.Core (in System.Core.dll)
'Declaration Public Shared Function ListInit ( _ newExpression As NewExpression, _ ParamArray initializers As Expression() _ ) As ListInitExpression
- Type: System.Linq.Expressions.NewExpression
newExpression or initializers is Nothing.
One or more elements of initializers are Nothing.
newExpression.Type does not implement IEnumerable.
There is no instance method named "Add" (case insensitive) declared in newExpression.Type or its base type.
The add method on newExpression.Type or its base type does not take exactly one argument.
The type represented by the Type property of the first element of initializers is not assignable to the argument type of the add method on newExpression.Type or its base type.
More than one argument-compatible method named "Add" (case-insensitive) exists on newExpression.Type and/or its base type.
In order to use this overload of , newExpression.Type or its base type must declare a single method named "Add" (case insensitive) that takes exactly one argument. The type of the argument must be assignable from the type represented by the Type property of the first element of initializers.
The Initializers property of the returned ListInitExpression contains one element of type ElementInit for each element of initializers. The Arguments property of each element of Initializers is a singleton collection that contains the corresponding element of initializers. The AddMethod property of each element of Initializers represents the add method that was discovered on newExpression.Type or its base type.
.NET FrameworkSupported in: 4.5, 4, 3.5
.NET Framework Client ProfileSupported in: 4, 3.5 SP1
Portable Class LibrarySupported in: Portable Class Library
.NET for Windows Store appsSupported in: Windows 8
.NET for Windows Phone appsSupported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8
Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.