缩短VB.NET数组声明?

时间:2010-09-15 12:12:54

标签: .net vb.net arrays

问题:如何缩短这个阵列的创建?
我需要使用一个属性创建一个ReportingService2005_W​​ebService.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"

1 个答案:

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