性能提示列表(共 T 个)

发布于 2024-10-15 14:51:13 字数 376 浏览 8 评论 0原文

我一直想在 VB.NET 中使用 List(Of T),而不是某个不能被命名的 Robinson 的 ArrayList。

本质上,我需要存储三件事:一个字符串、两个整数,也许还有两个布尔值。我喜欢使用 ArrayList,因为它将所有元素都视为“对象”,因此我在存储各种元素时并没有遇到任何问题。

但现在我一直在考虑使用List(Of T)。但是我该如何存储我的各种元素呢?我一直在考虑制作一个包含五个元素的结构。

听起来是个好主意吗?我在某处听说建筑物的寿命很短。但我担心只要我的应用程序存在,我就会永远拥有我的结构。这有什么区别吗?

最后,如果我需要创建......不知道...... 125,000,000 个列表,每个列表包含一个结构怎么办?这可能(而且很好)吗?

I have been tempted to use List(Of T) in VB.NET instead of ArrayLists by someone-who-must-not-be-named-Robinson.

Essentially, what I need to store are three things: One string, two integers, and maybe two booleans. I liked using ArrayList, because it treated all its elements as "Objects" so I didn't really have problems storing that variety of elements.

But now I have been thinking of using List(Of T). But how do I do to store that variety of elements of mine? I have been thinking on making a Structure holding the five elements.

Sounds like a good idea? I heard somewhere that Structures are expected to have a short life. But I fear I will be having my structures for... forever, as long as my application lives. Does that make any difference?

Finally, what if I needed to create... don't know...... 125,000,000 Lists, each containing a structure? Is that possible (and good)?

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

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

发布评论

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

评论(1

耶耶耶 2024-10-22 14:51:13

如果您使用集合类型(ArrayListList(Of T))只是因为您正在寻找一个位置来存储固定数量的完全不同类型,停止!尽管您正在寻找的称为,但您在创建结构方面走在正确的轨道上。

因为,从你的其他问题来看,听起来你正在创建一个地图编辑器,我假设你的两个数字是 X 和 Y 坐标,我猜这个字符串是某种名称?如果是这样,非常简单:(

Public Class Tile 
    Public Property Name as String
    Public Property X as Integer
    Public Property Y as Integer
End Class

请注意,上述内容仅在您使用 Visual Studio 2010 和 .NET 4 时才有效;如果没有,请回复,我将使用 4 之前的兼容版本进行编辑)

这会更容易您可以引用 .X.Y 属性,而不仅仅是到处乱扔索引。这也将比这样做更快(并且占用更少的内存)。

我将放弃对其中所有内容的完整描述,因为对类是什么和属性是什么的描述很容易获得。这有帮助吗?

If you're using a collection type (ArrayList or List(Of T)) just because you're looking for a place to store a fixed number of completely different types, stop! You're on the right track with creating a structure, though what you're looking for is called a class.

Since, from your other questions, it sounds like you're creating a map editor, I'm assuming that your two numbers are X and Y coordinates, and I'd guess the string is a name of some kind? If so, very simple:

Public Class Tile 
    Public Property Name as String
    Public Property X as Integer
    Public Property Y as Integer
End Class

(Note that the above will only work if you're using Visual Studio 2010 and .NET 4; if not, respond and I'll edit with a pre-4 compatible version)

It will be much easier for you to refer to the .X and .Y properties rather than just throwing indexes around all over the place. This will also be much much faster (and take up less memory) than doing that.

I'm going to forego a complete description of everything that's there, as descriptions of what a class is and what properties are is pretty readily available. Does that help?

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