性能问题:StringCollection与List< String> [英] Performance concern: StringCollection vs List<String>

查看:109
本文介绍了性能问题:StringCollection与List< String>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道何时应该使用 List<字符串> ,以及何时应使用 StringCollection .

I was wondering when I should use List< string > and when I should use StringCollection.

比方说,我必须处理大量字符串(例如10mb的文本文件).

Let's say that I have to deal with large number of strings (like text files of 10mb).

我知道 List< T> 提供的功能比 StringCollection .

I know that List< T > provides more powerful functions than StringCollection.

但是有时候我会找到列表< T> ,例如,告诉Gridview其数据源是List<字符串> ...

But sometimes I kind of find the List< T > slow when for example telling a Gridview that its datasource is a List< String >...

那么有人知道这些集合的优缺点,涉及内存的速度和重量吗?

关于它们的功能,我相信每个人都会同意说List是最好的,所以我的问题不是这个.考虑问题是有关Frameworks 4.0上的项目的,因此两者都可以使用.

Concerning their functionalities, I am sure everybody will agree to say that List is the best, so my question is not about that. Consider the question is about projects on Frameworks 4.0, so both can be used.

推荐答案

我个人更喜欢使用List<string>:

  • 无需记住仅用于字符串的一种特定类型
  • 它实现了通用的IEnumerable<T>而不是仅仅实现的IEnumerable,因此支持LINQ
  • SilverLight支持该功能
  • 对于大多数开发人员(IMO)来说,这更惯用了
  • No need to remember one specific type just for strings
  • It implements the generic IEnumerable<T> rather than just IEnumerable, and thus supports LINQ
  • It's supported in SilverLight
  • It's more idiomatic for most developers (IMO)

我真的很惊讶地发现StringCollection的速度明显快于List<string>-看看是否可以用数字来支持.我唯一犹豫的原因是GridView可能具有对StringCollection的硬编码支持,以使其能够快速使用该类型-但这对我来说似乎不太可能.

I would be really surprised to find StringCollection to be significantly faster than List<string> - see if you can back that up with numbers. My only cause for hesitation is that GridView could potentially have hard-coded support for StringCollection to make it fast with that type - but that sounds pretty unlikely to me.

这篇关于性能问题:StringCollection与List&lt; String&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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