“System.Collections.Generic”用户名和密码列表的最佳选择
我有一组用户名/密码对。用户名不能重复,但密码允许重复。
使用 System.Collections 我有很多选择,例如:
List<Dictionary<string, string>> accounts;
// or
System.Collections.Specialized.NameValueCollection[] accounts;
我们所有人都有程序员需要一组用户名/密码对的概念(获取已知用户名的密码,添加用户名/密码...)。
I have a set of username/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 ...).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
只需使用字典:
在泛型可用之前,
System.Collections.Specialized.NameValueCollection
类型是 .NET 第一个版本的一部分。最好尽可能使用通用集合。我还建议您不要以纯文本形式存储密码,以防万一您正在这样做。
Just use a Dictionary:
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.
我想我会简单地使用
字典中的键是unqiue。您可以在词典中添加/删除新用户。您可以从字典中查找/更改密码。
I think I would simply use
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.
仅使用
Dictionary
有什么问题?它可以让你做任何你需要做的事情。 (或者如果您需要快速检索,则可能是SortedDictionary
或SortedList
)What is the problem with using just a
Dictionary<string, string>
? It would allow you to do whatever you need. (Or maybeSortedDictionary<string, string>
orSortedList<string, string>
if you need fast retrieval)