什么是处理在C#中关联数组最简单的方法? [英] What is the easiest way to handle associative array in c#?

查看:144
本文介绍了什么是处理在C#中关联数组最简单的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有很多用C#经验,我从PHP用于关联数组。

I do not have a lot of experience with C#, and I am used from PHP with associative arrays.

我看到,在C#是List类和原数组,但我想一些字符串键在某一时刻相关联。

I see that in C# is the List class and the raw array, but I would like to associate some string keys at some moment.

什么是处理这个问题的最简单的方法是什么?

What is the easiest way to handle this?

THX!

推荐答案

使用Dictionary类。它应该做你所需要的。
参考是这里

Use the Dictionary class. It should do what you need. Reference is here.

所以,你可以做这样的事情:

So you can do something like this:

IDictionary<string, int> dict = new Dictionary<string, int>();
dict["red"] = 10;
dict["blue"] = 20;

这篇关于什么是处理在C#中关联数组最简单的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆