ElementInit 類別
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
代表 IEnumerable 集合中單一項目的初始設定式。
public ref class ElementInit sealed : System::Linq::Expressions::IArgumentProvider
public ref class ElementInit sealed
C#
public sealed class ElementInit : System.Linq.Expressions.IArgumentProvider
C#
public sealed class ElementInit
type ElementInit = class
interface IArgumentProvider
type ElementInit = class
Public NotInheritable Class ElementInit
Implements IArgumentProvider
Public NotInheritable Class ElementInit
- 繼承
-
ElementInit
- 實作
下列範例會建立 , ElementInit 表示字典集合之專案的初始化。
C#
string tree = "maple";
System.Reflection.MethodInfo addMethod = typeof(Dictionary<int, string>).GetMethod("Add");
// Create an ElementInit that represents calling
// Dictionary<int, string>.Add(tree.Length, tree).
System.Linq.Expressions.ElementInit elementInit =
System.Linq.Expressions.Expression.ElementInit(
addMethod,
System.Linq.Expressions.Expression.Constant(tree.Length),
System.Linq.Expressions.Expression.Constant(tree));
Console.WriteLine(elementInit.ToString());
// This code produces the following output:
//
// Void Add(Int32, System.String)(5,"maple")
Dim tree As String = "maple"
Dim addMethod As System.Reflection.MethodInfo = _
Type.GetType("System.Collections.Generic.Dictionary`2[System.Int32, System.String]").GetMethod("Add")
' Create an ElementInit that represents calling
' Dictionary(Of Integer, String).Add(tree.Length, tree).
Dim elementInit As System.Linq.Expressions.ElementInit = _
System.Linq.Expressions.Expression.ElementInit( _
addMethod, _
System.Linq.Expressions.Expression.Constant(tree.Length), _
System.Linq.Expressions.Expression.Constant(tree))
Console.WriteLine(elementInit.ToString())
' This code produces the following output:
'
' Void Add(Int32, System.String)(5,"maple")
Add |
取得可用來將項目加入 IEnumerable 集合的執行個體方法。 |
Arguments |
取得傳遞至方法的引數集合,該方法會將項目加入 IEnumerable 集合中。 |
Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
Get |
做為預設雜湊函式。 (繼承來源 Object) |
Get |
取得目前執行個體的 Type。 (繼承來源 Object) |
Memberwise |
建立目前 Object 的淺層複製。 (繼承來源 Object) |
To |
傳回 ElementInit 物件的文字形式。 |
Update(IEnumerable<Expression>) |
建立類似這個運算式的新運算式,但使用提供的子系。 如果所有子系都相同,則會傳回這個運算式。 |
IArgument |
傳回運算式樹狀節點的引數數目。 您不應該使用這個成員。 它只有在組件重構時為公用,且使用於內部以取得效能最佳化。 |
IArgument |
傳回位於索引的引數,如果索引超出範圍則擲回引數。 您不應該使用這個成員。 它只有在組件重構時為公用,且使用於內部以取得效能最佳化。 |
產品 | 版本 |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |