Expression.NewArrayInit Expression.NewArrayInit Expression.NewArrayInit Method

定義

1 次元配列の作成と、要素のリストからの初期化を表す NewArrayExpression を作成します。Creates a NewArrayExpression that represents creating a one-dimensional array and initializing it from a list of elements.

オーバーロード

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

1 次元配列の作成と、要素のリストからの初期化を表す NewArrayExpression を作成します。Creates a NewArrayExpression that represents creating a one-dimensional array and initializing it from a list of elements.

NewArrayInit(Type, Expression[]) NewArrayInit(Type, Expression[]) NewArrayInit(Type, Expression[])

1 次元配列の作成と、要素のリストからの初期化を表す NewArrayExpression を作成します。Creates a NewArrayExpression that represents creating a one-dimensional array and initializing it from a list of elements.

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

1 次元配列の作成と、要素のリストからの初期化を表す NewArrayExpression を作成します。Creates a NewArrayExpression that represents creating a one-dimensional array and initializing it from a list of elements.

public:
 static System::Linq::Expressions::NewArrayExpression ^ NewArrayInit(Type ^ type, System::Collections::Generic::IEnumerable<System::Linq::Expressions::Expression ^> ^ initializers);
public static System.Linq.Expressions.NewArrayExpression NewArrayInit (Type type, System.Collections.Generic.IEnumerable<System.Linq.Expressions.Expression> initializers);
static member NewArrayInit : Type * seq<System.Linq.Expressions.Expression> -> System.Linq.Expressions.NewArrayExpression

パラメーター

type
Type Type Type

配列の要素の型を表す TypeA Type that represents the element type of the array.

initializers
IEnumerable<Expression>

IEnumerable<T> コレクションへの読み込みに使用する Expression オブジェクトを含む ExpressionsAn IEnumerable<T> that contains Expression objects to use to populate the Expressions collection.

戻り値

NewArrayExpression と等しい NodeType プロパティおよび指定した値に設定された NewArrayInit プロパティを含む ExpressionsA NewArrayExpression that has the NodeType property equal to NewArrayInit and the Expressions property set to the specified value.

例外

type または initializersnull です。type or initializers is null.

または-or- initializers の要素は null です。An element of initializers is null.

initializers の要素の Type プロパティは、type が表す型に代入できない型を表します。The Type property of an element of initializers represents a type that is not assignable to the type that type represents.

次の例では、使用する方法、 NewArrayInit 1 次元の文字列配列の作成を表す式ツリーを作成するメソッドは文字列式のリストで初期化されます。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.

List<System.Linq.Expressions.Expression> trees =
    new List<System.Linq.Expressions.Expression>()
        { System.Linq.Expressions.Expression.Constant("oak"),
          System.Linq.Expressions.Expression.Constant("fir"),
          System.Linq.Expressions.Expression.Constant("spruce"),
          System.Linq.Expressions.Expression.Constant("alder") };

// Create an expression tree that represents creating and  
// initializing a one-dimensional array of type string.
System.Linq.Expressions.NewArrayExpression newArrayExpression =
    System.Linq.Expressions.Expression.NewArrayInit(typeof(string), trees);

// Output the string representation of the Expression.
Console.WriteLine(newArrayExpression.ToString());

// This code produces the following output:
//
// new [] {"oak", "fir", "spruce", "alder"}
Dim trees As New System.Collections.Generic.List(Of System.Linq.Expressions.Expression) _
        (New System.Linq.Expressions.Expression() _
         {System.Linq.Expressions.Expression.Constant("oak"), _
          System.Linq.Expressions.Expression.Constant("fir"), _
          System.Linq.Expressions.Expression.Constant("spruce"), _
          System.Linq.Expressions.Expression.Constant("alder")})

' Create an expression tree that represents creating and  
' initializing a one-dimensional array of type string.
Dim newArrayExpression As System.Linq.Expressions.NewArrayExpression = _
    System.Linq.Expressions.Expression.NewArrayInit(Type.GetType("System.String"), trees)

' Output the string representation of the Expression.
Console.WriteLine(newArrayExpression.ToString())

' This code produces the following output:
'
' new [] {"oak", "fir", "spruce", "alder"}

注釈

Typeの各要素のプロパティinitializersによって表される型に割り当て可能な型を表す必要がありますtype、場合によってはその後引用符で囲まれたします。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.

注意

要素は引用符で囲む場合にのみtypeExpressionします。An element will be quoted only if type is Expression. 要素にラップする手段を引用符で囲む、Quoteノード。Quoting means the element is wrapped in a Quote node. 見つかったノードが、UnaryExpressionOperandプロパティは、要素のinitializersします。The resulting node is a UnaryExpression whose Operand property is the element of initializers.

TypeプロパティNewArrayExpression表します型の配列のランクは 1 と要素型があるtypeします。The Type property of the resulting NewArrayExpression represents an array type whose rank is 1 and whose element type is type.

NewArrayInit(Type, Expression[]) NewArrayInit(Type, Expression[]) NewArrayInit(Type, Expression[])

1 次元配列の作成と、要素のリストからの初期化を表す NewArrayExpression を作成します。Creates a NewArrayExpression that represents creating a one-dimensional array and initializing it from a list of elements.

public:
 static System::Linq::Expressions::NewArrayExpression ^ NewArrayInit(Type ^ type, ... cli::array <System::Linq::Expressions::Expression ^> ^ initializers);
public static System.Linq.Expressions.NewArrayExpression NewArrayInit (Type type, params System.Linq.Expressions.Expression[] initializers);
static member NewArrayInit : Type * System.Linq.Expressions.Expression[] -> System.Linq.Expressions.NewArrayExpression

パラメーター

type
Type Type Type

配列の要素の型を表す TypeA Type that represents the element type of the array.

initializers
Expression[]

Expression コレクションへの読み込みに使用する Expressions オブジェクトの配列。An array of Expression objects to use to populate the Expressions collection.

戻り値

NewArrayExpression と等しい NodeType プロパティおよび指定した値に設定された NewArrayInit プロパティを含む ExpressionsA NewArrayExpression that has the NodeType property equal to NewArrayInit and the Expressions property set to the specified value.

例外

type または initializersnull です。type or initializers is null.

または-or- initializers の要素は null です。An element of initializers is null.

initializers の要素の Type プロパティは、type 型に代入可能な型を表します。The Type property of an element of initializers represents a type that is not assignable to the type type.

次の例では、使用する方法、 NewArrayInit 1 次元の文字列配列の作成を表す式ツリーを作成するメソッドは文字列式のリストで初期化されます。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.

List<System.Linq.Expressions.Expression> trees =
    new List<System.Linq.Expressions.Expression>()
        { System.Linq.Expressions.Expression.Constant("oak"),
          System.Linq.Expressions.Expression.Constant("fir"),
          System.Linq.Expressions.Expression.Constant("spruce"),
          System.Linq.Expressions.Expression.Constant("alder") };

// Create an expression tree that represents creating and  
// initializing a one-dimensional array of type string.
System.Linq.Expressions.NewArrayExpression newArrayExpression =
    System.Linq.Expressions.Expression.NewArrayInit(typeof(string), trees);

// Output the string representation of the Expression.
Console.WriteLine(newArrayExpression.ToString());

// This code produces the following output:
//
// new [] {"oak", "fir", "spruce", "alder"}
Dim trees As New System.Collections.Generic.List(Of System.Linq.Expressions.Expression) _
        (New System.Linq.Expressions.Expression() _
         {System.Linq.Expressions.Expression.Constant("oak"), _
          System.Linq.Expressions.Expression.Constant("fir"), _
          System.Linq.Expressions.Expression.Constant("spruce"), _
          System.Linq.Expressions.Expression.Constant("alder")})

' Create an expression tree that represents creating and  
' initializing a one-dimensional array of type string.
Dim newArrayExpression As System.Linq.Expressions.NewArrayExpression = _
    System.Linq.Expressions.Expression.NewArrayInit(Type.GetType("System.String"), trees)

' Output the string representation of the Expression.
Console.WriteLine(newArrayExpression.ToString())

' This code produces the following output:
'
' new [] {"oak", "fir", "spruce", "alder"}

注釈

Typeの各要素のプロパティinitializersによって表される型に割り当て可能な型を表す必要がありますtype、場合によってはその後引用符で囲まれたします。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.

注意

要素は引用符で囲む場合にのみtypeExpressionします。An element will be quoted only if type is Expression. 要素にラップする手段を引用符で囲む、Quoteノード。Quoting means the element is wrapped in a Quote node. 見つかったノードが、UnaryExpressionOperandプロパティは、要素のinitializersします。The resulting node is a UnaryExpression whose Operand property is the element of initializers.

TypeプロパティNewArrayExpression表します型の配列のランクは 1 と要素型があるtypeします。The Type property of the resulting NewArrayExpression represents an array type whose rank is 1 and whose element type is type.

適用対象