简体   繁体   中英

What's the difference between System.Collections, System.Collections.Specialized, and System.Collections.Generic in .NET?

What is the major difference between the three? Right now, I want to create a key/value pair using both string/string respectively. All three seem to have options I can use.

Edit: I just want to create a simple hash table - nothing really complex.

The generic collections almost completely replace the base collections and Collections.Specialized. To really give the best recommendation we need to know more about what you want to do, but odds are you want System.Collections.Generic.Dictionary .

  • System.Collections : containers that store references to System.Object types
  • System.Collections.Specialized : specialized versions of System.Collections for types other than System.Object (distinct collection types per specialization, each stored in assembly)
  • System.Collections.Generic : a replacement for the above two as the runtime will determine how to create the collection for the type you want stored in it (one collection type for all specializations).

The answer is highly dependent on your usage. Without knowing details, I would say take a look at System.Collections.Specialized.NameValueCollection for string, string. System.Collections.Specialized & System.Collections.Generic are strongly typed, I think System.Collections is just left over from .NET 1.1.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM