C# PHP 风格数组键

发布于 2024-10-08 20:15:45 字数 185 浏览 0 评论 0原文

我有一个字符串数组:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

楠木可依 2024-10-15 20:15:45

使用 System.Collections.Generic.Dictionary

例如:

Dictionary<string, string> myDictionary = new Dictionary<string, string>();

myDictionary.Add("key", "value");

string foo = myDictionary["key"];

Dictionary 有一些您可能会觉得有用的方法,例如ContainsKey().

Use System.Collections.Generic.Dictionary<TKey, TValue>.

For example:

Dictionary<string, string> myDictionary = new Dictionary<string, string>();

myDictionary.Add("key", "value");

string foo = myDictionary["key"];

Dictionary<TKey, TValue> has some methods that you might find useful, such as ContainsKey().

绮筵 2024-10-15 20:15:45

使用字典

Dictionary<String,Object> phpArray = new Dictionary<String,Object>();
phpArray.Add("keyhere",1);
MessageBox.Show(phpArray["keyhere"]);

Use a dictionary

Dictionary<String,Object> phpArray = new Dictionary<String,Object>();
phpArray.Add("keyhere",1);
MessageBox.Show(phpArray["keyhere"]);
花之痕靓丽 2024-10-15 20:15:45

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#.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文