C# collection initializers provide the same functionality as Visual Basic collection initializers. For more information about C# collection initializers, see Object and Collection Initializers. Syntax A collect
如果集合没有这样一个 Add 方法,您可以创建一个扩展方法。如何给集合添加扩展方法的例子,参见How to: Create an Add Extension Method Used by a Collection Initializer。如何创建带集合初始化器的自定义集合(custom collection),参见Create a Collection Used by a Collection Initializer。 嵌套的集合初始化器 您可...
Microsoft.CodeAnalysis.VisualBasic.dll Paquet: Microsoft.CodeAnalysis.VisualBasic v4.13.0 Source: Syntax.xml.Syntax.Generated.vb C# publicMicrosoft.CodeAnalysis.VisualBasic.Syntax.CollectionInitializerSyntaxAddInitializers(paramsMicrosoft.CodeAnalysis.VisualBasic.Syntax.ExpressionSyntax[] items); ...
' Create a list of strings by using a' collection initializer.DimsalmonsAsNewList(OfString)From{"chinook","coho","pink","sockeye"}ForEachsalmonAsStringInsalmons Console.Write(salmon &" ")Next'Output: chinook coho pink sockeye 可以使用For…Next语句,而不是For Each语句来循环访问集合。 通过按索...
' Create a list of strings by using a' collection initializer.DimsalmonsAsNewList(OfString)From{"chinook","coho","pink","sockeye"}ForEachsalmonAsStringInsalmons Console.Write(salmon &" ")Next'Output: chinook coho pink sockeye You can use aFor…Next(Visual Basic) orfor(C#) statement instea...
' Create a list of strings by using a ' collection initializer. Dim lst As New List(Of String) _ From {"abc", "def", "ghi"} ' Iterate through the list. For Each item As String In lst Debug.Write(item & " ") Next Debug.WriteLine("") 'Output: abc def ghi 如需更多範例,...
CollectionInitializer(SyntaxToken, SeparatedSyntaxList<ExpressionSyntax>, SyntaxToken) Represents an expression that creates a new array without naming the element type. CollectionRangeVariable(ModifiedIdentifierSyntax, ExpressionSyntax) Describes a single variable of the form "x [As Type] In ex...
Last week at theProfessional Developers Conference, we made a number of very exciting announcements regarding the future of Visual Basic. Here is the list of VB 2010 features we’ve announced: Collection Initializers. Initialize collections in fewer lines of code! Use the “From” keyword followed...
dotnet_style_collection_initializer=true:suggestion dotnet_style_explicit_tuple_names=true:suggestion dotnet_style_null_propagation=true:suggestion dotnet_style_object_initializer=true:suggestion dotnet_style_parentheses_in_arithmetic_binary_operators=always_for_clarity:silent ...
of an anonymous type, that is (using pseudo-code)IEnumerable(Of { Name As String, Country As String }). The Visual Basic compiler will create an implicit class, for example,_Name_As_String_Country_As_String_, whose member names and types are inferred from the object initializer, as ...