Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
ElementInit Method (MethodInfo, Expression[])

Expression::ElementInit Method (MethodInfo, array<Expression>)

Creates an ElementInit, given an array of values as the second argument.

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

static ElementInit^ ElementInit(
	MethodInfo^ addMethod, 
	... array<Expression^>^ arguments


Type: System.Reflection::MethodInfo

A MethodInfo to set the AddMethod property equal to.

Type: array<System.Linq.Expressions::Expression>

An array of Expression objects to set the Arguments property equal to.

Return Value

Type: System.Linq.Expressions::ElementInit
An ElementInit that has the AddMethod and Arguments properties set to the specified values.


addMethod or arguments is nullptr.


The method that addMethod represents is not named "Add" (case insensitive).


The method that addMethod represents is not an instance method.


arguments does not contain the same number of elements as the number of parameters for the method that addMethod represents.


The Type property of one or more elements of arguments is not assignable to the type of the corresponding parameter of the method that addMethod represents.

The addMethod parameter must represent an instance method named "Add" (case insensitive). The add method must have the same number of parameters as the number of elements in arguments. The Type property of each element in arguments must be assignable to the type of the corresponding parameter of the add method, possibly after quoting.


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

The following example demonstrates how to use the ElementInit(MethodInfo, array<Expression>) method to create an ElementInit that represents calling the Add method to initialize an element of a dictionary collection.

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