C#最快的容器? [英] C# fastest container ?
问题描述
http://stackoverflow.com/questions / 471432 / in-scenario-do-i-use-a-specific-stl-container [ ^ ]
就像在这个问题中,你们有一个流程图或其他东西为我在C#中选择最好的容器吗?
我想存储一些int。我不能使用int []数组,因为它不可插入..
我的意思是我无法随时插入一个函数,如foo.Add(val)或foo.Insert(val)with arrays 。
而且我不在乎它是不是有秩序或什么的。我想要的只是容器中的整数,并在我想要的时候添加更多的整数。
然后使用foreach()循环遍历容器!
<我应该使用哪个容器?<br />
任何流程图都会很棒。
提前感谢!
http://stackoverflow.com/questions/471432/in-which-scenario-do-i-use-a-particular-stl-container[^]
just like in this question, do u guys have a flowchart or something to select the best container for my purpose in C# ?
I want to store some int s. I cant use an int[] array because it's not insertable..
I mean i cant insert whenever I want with a single function like foo.Add(val) or foo.Insert(val) with arrays.
And I dont care if it's not in order or anything. All I want is those integers from the container and add more integers into it whenever I want.
And loop through the container using a foreach() loop of course !
which container should I use ?
any flowchart would be great.
thanks in advance !
推荐答案
只需使用列表< int>
- 但如果你不在乎关于订单做一些定时测试,看看Add或Insert是否更快 - 可能在头部使用Insert会更快,因为不需要遍历列表来找到最终值。
Just use a List<int>
- but if you don't care about order do some timing tests at see if Add or Insert is faster - it's possible that using Insert at the head will be faster because there would be no need to traverse the list to find the final value.
这篇关于C#最快的容器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!