是在c#字符串的字符串数组和列表之间的区别 [英] what is difference between string array and list of string in c#

查看:105
本文介绍了是在c#字符串的字符串数组和列表之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我听到 MSDN 的一个数组比集合快。

I hear on MSDN that an array is faster than a collection.

您可以告诉我怎么的String [] 快则列表<字符串方式>

Can you tell me how string[] is faster then List<string>.

推荐答案

数组是不是集合,如清单较低层次的抽象。在CLR知道阵列直接,所以有略少的工作涉及迭代,访问等。

Arrays are a lower level abstraction than collections such as lists. The CLR knows about arrays directly, so there's slightly less work involved in iterating, accessing etc.

不过,这应该差不多的从不的决定你实际使用。性能差异将是最现实世界的应用可以忽略不计。我很少能找到适合使用的阵列,而不是各种泛型集合类,确实有些人认为<一href=\"http://blogs.msdn.com/b/ericlippert/archive/2008/09/22/arrays-considered-somewhat-harmful.aspx\">arrays有些有害。一个显著的缺点是,有没有这样的事,作为一个不可变的数组(比空除外)...,而您可以通过一个API比较容易暴露只读集合。

However, this should almost never dictate which you actually use. The performance difference will be negligible in most real-world applications. I rarely find it appropriate to use arrays rather than the various generic collection classes, and indeed some consider arrays somewhat harmful. One significant downside is that there's no such thing as an immutable array (other than an empty one)... whereas you can expose read-only collections through an API relatively easily.

这篇关于是在c#字符串的字符串数组和列表之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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