Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
262 views
in Technique[技术] by (71.8m points)

c# - Performance concern: StringCollection vs List<String>

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

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

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

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

So do anyone know the pros and cons of these collections, concerning speed and weight in memory?

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.

question from:https://stackoverflow.com/questions/7774374/performance-concern-stringcollection-vs-liststring

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I would personally prefer to use List<string>:

  • 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)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...