'System.Collections.Generic' best choice for a list of username and passwords
I have a set of u开发者_开发问答sername/password pairs. There are no duplicate usernames but passwords duplication is allowed.
Using System.Collections
I have many choices for example:
List<Dictionary<string, string>> accounts;
// or
System.Collections.Specialized.NameValueCollection[] accounts;
All of us have the concepts of what a programmer needs with a set of username/password pair (get password of a known username, add a username/password ...).
Just use a Dictionary:
Dictionary<string, string> accounts
The type System.Collections.Specialized.NameValueCollection
was part of the first version of .NET, before generics were available. It is better to use a generic collection where possible.
I'd also advise you not to store the passwords in plain text, in case that's what you are doing.
I think I would simply use
Dictionary<string, SecureString>
The keys in dictionary are unqiue. You can add/remove new user to your dictionary. You can lookup/change password from dictionary.
Sounds to me like you want a Hashtable.
What is the problem with using just a Dictionary<string, string>
? It would allow you to do whatever you need. (Or maybe SortedDictionary<string, string>
or SortedList<string, string>
if you need fast retrieval)
精彩评论