Question: How to shorten this array creation ?
I need to create an array of type ReportingService2005_WebService.Property with one property.Something like:
Dim PropertyArray() as new ReportingService2005_WebService.Property(1)
I have to do this:
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"
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" } _
}
Make sure your "array brackets" are in the correct place in the initial Dim statement. Should be: Dim PropertyArray()...
精彩评论