NewArrayExpression 類別

定義

代表建立新陣列,並可能初始化新陣列的項目。

public ref class NewArrayExpression : System::Linq::Expressions::Expression
public ref class NewArrayExpression sealed : System::Linq::Expressions::Expression
public class NewArrayExpression : System.Linq.Expressions.Expression
public sealed class NewArrayExpression : System.Linq.Expressions.Expression
type NewArrayExpression = class
    inherit Expression
Public Class NewArrayExpression
Inherits Expression
Public NotInheritable Class NewArrayExpression
Inherits Expression
繼承
NewArrayExpression

範例

下列範例會 NewArrayExpression 建立 物件,代表建立和初始化字串的一維陣列。

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"}

下一個 NewArrayExpression 範例會建立 物件,代表建立字串的二維陣列。

// Create an expression tree that represents creating a
// two-dimensional array of type string with bounds [3,2].
System.Linq.Expressions.NewArrayExpression newArrayExpression =
    System.Linq.Expressions.Expression.NewArrayBounds(
            typeof(string),
            System.Linq.Expressions.Expression.Constant(3),
            System.Linq.Expressions.Expression.Constant(2));

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

// This code produces the following output:
//
// new System.String[,](3, 2)
' Create an expression tree that represents creating a string
' array with rank 2 and bounds (3,2).
Dim newArrayExpression As System.Linq.Expressions.NewArrayExpression = _
    System.Linq.Expressions.Expression.NewArrayBounds( _
            Type.GetType("System.String"), _
            System.Linq.Expressions.Expression.Constant(3), _
            System.Linq.Expressions.Expression.Constant(2))

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

' This code produces the following output:
'
' new System.String[,](3, 2)

備註

下表顯示您可以視 NodeType 需要使用的不同 Factory 方法來建立 NewArrayExpression

NodeType Factory 方法
NewArrayBounds NewArrayBounds
NewArrayInit NewArrayInit

屬性

CanReduce

表示節點可精簡為更簡單的節點。 如果傳回 true,則可呼叫 Reduce() 以產生精簡的形式。

(繼承來源 Expression)
Expressions

如果 NodeType 屬性的值是 NewArrayBounds,則取得陣列的界限,如果 NodeType 屬性的值是 NewArrayInit,則取得值以初始化新陣列的項目。

NodeType

取得這個 Expression 的節點類型。

(繼承來源 Expression)
Type

取得此 Expression 代表之運算式的靜態類型。

Type

取得此 Expression 代表之運算式的靜態類型。

(繼承來源 Expression)

方法

Accept(ExpressionVisitor)

分派給這個節點類型的特定造訪方法。 例如,MethodCallExpression 會呼叫 VisitMethodCall(MethodCallExpression)

Accept(ExpressionVisitor)

分派給這個節點類型的特定造訪方法。 例如,MethodCallExpression 會呼叫 VisitMethodCall(MethodCallExpression)

(繼承來源 Expression)
Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
Reduce()

將這個節點精簡為更簡單的運算式。 如果 CanReduce 傳回 true,則應該傳回有效的運算式。 這個方法可以傳回其他本身必須精簡的節點。

(繼承來源 Expression)
ReduceAndCheck()

將這個節點精簡為更簡單的運算式。 如果 CanReduce 傳回 true,則應該傳回有效的運算式。 這個方法可以傳回其他本身必須精簡的節點。

(繼承來源 Expression)
ReduceExtensions()

將運算式精簡為已知的節點類型 (不是 Extension 節點),如果已經是已知的類型,則僅傳回運算式。

(繼承來源 Expression)
ToString()

傳回 Expression 的文字表示。

(繼承來源 Expression)
Update(IEnumerable<Expression>)

建立類似這個運算式的新運算式,但使用提供的子系。 如果所有子系都相同,則會傳回這個運算式。

VisitChildren(ExpressionVisitor)

精簡節點,然後呼叫精簡後的運算式上的訪問項委派。 如果節點無法縮減,此方法會擲回例外狀況。

(繼承來源 Expression)

適用於