小编Kly*_*roe的帖子

具有多个值的ArrayList c#

我不确定这是否可以使用ArrayList或Dictionary,或者它是否是其他东西,如果是这样我想知道你在哪里可以指出我正确的方向......

你有一个具有多个值的ArrayList,即

ArrayList weather = new ArrayList();
weather.Add("Sunny", "img/sunny.jpg");
weather.Add("Rain", "img/Rain.jpg);
Run Code Online (Sandbox Code Playgroud)

然后分配给下面的控件.

if (WeatherValue = 0)
{
   Label1.Text = weather[0].ToString;
   Image1.ImageUrl = weather[0].ToString;
}
Run Code Online (Sandbox Code Playgroud)

或者我可以用词典做到这一点

Dictionary<string, string> dict = new Dictionary<string, string>();
dict.Add("Cloudy", "../img/icons/w0.png");  //[0]
dict.Add("Rain", "../img/icons/w1.png");    //[1]  

Label1.Text = dict[0].VALUE1;    //So this would get Cloudy
Image.ImageUrl = dict[0].VALUE2; //This would get ../img/w0.png
Run Code Online (Sandbox Code Playgroud)

如何使用[0]和[1]分别调用字典的值?等等

c# arrays dictionary arraylist

1
推荐指数
1
解决办法
5050
查看次数

标签 统计

arraylist ×1

arrays ×1

c# ×1

dictionary ×1