泛型列表比较到一个数组 [英] Comparing generic list to an array

查看:151
本文介绍了泛型列表比较到一个数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么generic.list比数组慢?

Why is the generic.list slower than array?

推荐答案

一个泛型列表比数组稍微慢一些,但没那么你会发现在大多数情况下。大多它必须做与查找稍微更复杂:列表据说用引擎盖下的阵列,但它不是不能保证保持节点相邻的存储器中的相同的方式在阵列。

A generic list is slightly slower than an array, but not so you'd notice in most cases. Mostly it has to do with the lookup being slightly more complex: List is said to use an array "under the hood", but it's not not guaranteed to keep nodes in adjacent memory in the same way in array is.

不过,我看到了一些基准,早在2005年(找不到现在的链接),不同的是非常的小。

However, I saw some benchmarks way back in 2005 (can't find the link now) and difference is very small.

此外,该列表中有一些对数组重要的优势:主要是是微不足道的添加或删除项目。它更容易使用,当你不知道有多少项目,你需要,或者当这个数字会有所不同的列表。在这种情况下(和诚实,这是的的大部分时间的),你应该的没有的使用数组。

Also, the list has a number of important advantages over an array: mainly that it's trivial to add or remove items. It's much easier to use a list when you don't know how many items you will need, or when that number will vary. In those cases (and honestly, that's most of the time), you probably should not use an array.

这篇关于泛型列表比较到一个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆