gpt4 book ai didi

.net - 缩短 VB.NET 数组声明?

转载 作者:行者123 更新时间:2023-12-04 06:46:25 26 4
gpt4 key购买 nike

问题:如何缩短这个数组的创建?
我需要使用一个属性创建一个 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"

最佳答案

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 语句中的正确位置。应该:
昏暗的 PropertyArray()...

关于.net - 缩短 VB.NET 数组声明?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3717452/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com