C# PHP 风格数组键
我有一个字符串数组:
String[] array1 = new String[10];
我是否可以使用 nto 数字的键?
array["keyhere"] instead of array1[1]
有人知道怎么做吗?
I have a string array:
String[] array1 = new String[10];
Is there anyway I can use keys which are nto numbers?
array["keyhere"] instead of array1[1]
anyone know how?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用
System.Collections.Generic.Dictionary
。例如:
Dictionary
有一些您可能会觉得有用的方法,例如ContainsKey()
.Use
System.Collections.Generic.Dictionary<TKey, TValue>
.For example:
Dictionary<TKey, TValue>
has some methods that you might find useful, such asContainsKey()
.使用字典
Use a dictionary
PHP 数组称为关联数组。您可以使用 Dictionary 或 HashMap 在 C# 中实现相同的功能。
PHP arrays are called associative arrays. You can use either a Dictionary or HashMap to implement the same thing in C#.