性能提示列表(共 T 个)
我一直想在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用集合类型(
ArrayList
或List(Of T)
)只是因为您正在寻找一个位置来存储固定数量的完全不同类型,停止!尽管您正在寻找的称为类
,但您在创建结构方面走在正确的轨道上。因为,从你的其他问题来看,听起来你正在创建一个地图编辑器,我假设你的两个数字是 X 和 Y 坐标,我猜这个字符串是某种名称?如果是这样,非常简单:(
请注意,上述内容仅在您使用 Visual Studio 2010 和 .NET 4 时才有效;如果没有,请回复,我将使用 4 之前的兼容版本进行编辑)
这会更容易您可以引用
.X
和.Y
属性,而不仅仅是到处乱扔索引。这也将比这样做更快(并且占用更少的内存)。我将放弃对其中所有内容的完整描述,因为对类是什么和属性是什么的描述很容易获得。这有帮助吗?
If you're using a collection type (
ArrayList
orList(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 aclass
.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:
(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?