views:

57

answers:

1

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"
+3  A: 

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()...

Zippit
@Zippit: what version of VB.NET is required? E.g. would it work with the version of VB.NET corresponding to Visual Studio 2008?
Peter Mortensen
I'm using 2008 and this syntax works fine.
David_Jarrett
as per that link in my post it is VB.NET v9, which is VS2008.
Zippit