问题:如何缩短这个阵列的创建?
我需要使用一个属性创建一个ReportingService2005_WebService.Property类型的数组。
类似的东西:
Dim PropertyArray() as new ReportingService2005_WebService.Property(1)
我必须这样做:
Dim PropertyArray As ReportingService2005_WebService.Property() = New ReportingService2005_WebService.Property(0) {}
PropertyArray(0) = New ReportingService2005_WebService.Property
PropertyArray(0).Name = "Description"
PropertyArray(0).Value = "Automatically added DataSource"
答案 0 :(得分:3)
http://blogs.msdn.com/b/wriju/archive/2008/02/05/vb-net-9-0-object-and-array-initializers.aspx
Dim PropertyArray() As ReportingService2005_WebService.Property = { _
new ReportingService2005_WebService.Property() With {.Name = "Description", .Value="Automatically added DataSource" } _
}
确保您的“数组括号”位于初始Dim语句中的正确位置。应该: Dim PropertyArray()......