.NET - 我想这样做:Dim D as new Dictionary(of String, Array(OF MYOBJECT))

发布于 2024-08-08 23:58:07 字数 328 浏览 5 评论 0原文

我想创建一个由字符串索引的字典: Dictionary(of String, ...)

我希望逗号后面的类型是 MyObject 的数组。

如果我所做的只是以下内容:

Dim D as new Dictionary(of String, Array)

我觉得每次访问成员时我都错过了一些性能:

Dim Object1 as MyObject = MyDictionary("Key1")(4)

它是否必须执行某种类型的查找来找出数组每次保存的对象类型我以这种方式访问​​它?

I'd like to create a Dictionary that is indexed by Strings: Dictionary(of String, ...)

I'd like the Type after the comma to be an Array of MyObject's.

If all I do is the following:

Dim D as new Dictionary(of String, Array)

I feel like I'm missing out on some performance very time I access a member:

Dim Object1 as MyObject = MyDictionary("Key1")(4)

Doesn't it have to perform some type of lookup to figure out what type of object the array is holding every time I access it in this manner?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

守护在此方 2024-08-15 23:58:07

如果 Value 确实需要是 MyObject 的数组,您可以执行以下操作:

Dim D as new Dictionary(of String, MyObject())

If the Value really needs to be an array of MyObject, you could do the following:

Dim D as new Dictionary(of String, MyObject())
柠檬心 2024-08-15 23:58:07

Array 不是你想要的;相反,使用您想要的强类型数组:

Dim D as New Dictionary(Of String, MyObject())()

这就像一个魅力。

Array isn’t what you want; rather, use the strongly typed array that you want to have:

Dim D as New Dictionary(Of String, MyObject())()

This works like a charm.

逆流 2024-08-15 23:58:07

使用数组,您在检索它时将调用类型转换。这个怎么样:

Dim D as new Dictionary(of String, List(of MyObject))

Using array, you will be invoking type casting when you retrieve it. How about this:

Dim D as new Dictionary(of String, List(of MyObject))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文