VB.Net 等效于索引器初始化程序
VB.Net equivalent for Indexer Initializer
是否有任何 VB.NET 等效于 C#6 索引器初始化构造?
var placesByZip = new Dictionary<string, string>
{
["63368"] = "Dardenne Prairie",
["63141"] = "Des Peres",
["63101"] = "St. Louis"
};
--编辑--
更准确地说,我正在寻找 Indexer Initializer(它是一个对象初始化器),而不是集合初始化器。
有关差异的更多信息,请参阅本文末尾 blog entry。
-- 编辑 2:
从提到的博客来看,解决方案应该允许这样做:
Again, I wish to reiterate that the Indexer Initializer is not a type
of Collection Initializer, it’s a type of Object Initializer. Why do
I keep saying this? Why is this distinction important? Because you
cannot mix object initializers and collection initializers in the same
initialization list.
So, we can’t initialize a collection and set a property in the same
initialization list, but we can set a property, field, and indexer in
the same initialization list since they are all valid Object
Initializers.
应该是
Dim placesByZip as New Dictionary(Of String, String) From {
{"63368", "Dardenne Prairie"},
{"63141", "Des Peres"},
{"63101", "St. Louis"}
}
(之前没试过)
是
Dim placesByZip As New Dictionary(Of String, String) From {
{"63368", "Dardenne Prairie"},
{"63141", "Des Peres"},
{"63101", "St. Louis"}}
Visual Basic 中没有这样的功能。
https://docs.microsoft.com/en-us/dotnet/visual-basic/getting-started/whats-new
截至 2019-06-27,VB.NET 版本 15.8 (VS 2017),未根据 Microsoft documentation on object initializers.
授权索引成员的对象初始化
Class members being initialized cannot be indexed or qualified
中均未提及
是否有任何 VB.NET 等效于 C#6 索引器初始化构造?
var placesByZip = new Dictionary<string, string>
{
["63368"] = "Dardenne Prairie",
["63141"] = "Des Peres",
["63101"] = "St. Louis"
};
--编辑--
更准确地说,我正在寻找 Indexer Initializer(它是一个对象初始化器),而不是集合初始化器。
有关差异的更多信息,请参阅本文末尾 blog entry。
-- 编辑 2:
从提到的博客来看,解决方案应该允许这样做:
Again, I wish to reiterate that the Indexer Initializer is not a type of Collection Initializer, it’s a type of Object Initializer. Why do I keep saying this? Why is this distinction important? Because you cannot mix object initializers and collection initializers in the same initialization list.
So, we can’t initialize a collection and set a property in the same initialization list, but we can set a property, field, and indexer in the same initialization list since they are all valid Object Initializers.
应该是
Dim placesByZip as New Dictionary(Of String, String) From {
{"63368", "Dardenne Prairie"},
{"63141", "Des Peres"},
{"63101", "St. Louis"}
}
(之前没试过)
是
Dim placesByZip As New Dictionary(Of String, String) From {
{"63368", "Dardenne Prairie"},
{"63141", "Des Peres"},
{"63101", "St. Louis"}}
Visual Basic 中没有这样的功能。
https://docs.microsoft.com/en-us/dotnet/visual-basic/getting-started/whats-new
截至 2019-06-27,VB.NET 版本 15.8 (VS 2017),未根据 Microsoft documentation on object initializers.
授权索引成员的对象初始化中均未提及Class members being initialized cannot be indexed or qualified