111,129
社区成员
发帖
与我相关
我的任务
分享
Dictionary<int, string> dict = new Dictionary<int, string>();
dict.Add(1, "helo");
dict.Add(2, "helo");
int[] keys = new int[dict.Count];
dict.Keys.CopyTo(keys, 0);
foreach (int key in keys)
{
Response.Write("key"+key.ToString()+":" + key.ToString());
dict.Remove(key);
// Response.Write("key" + key.ToString() + ":" + dict[key]);
}
Dictionary<string, string> a = new Dictionary<string,string>(); foreach( string key in a.Keys) { a[key] = ... }
Dictionary<string, string> a = new Dictionary<string,string>();
foreach( string key in a.Keys)
{
a[key] = ...
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main()
{
//初始化dictionary对象
Dictionary<string, string> dict1 = new Dictionary<string, string>();
dict1.Add("LeftValue", "1");
List<DictValue> listDict = new List<DictValue>();
Dictionary<string, string>.KeyCollection kc = dict1.Keys;
Dictionary<string, string>.ValueCollection vc = dict1.Values;
foreach(string k1 in kc)
foreach (string v1 in vc)
{
DictValue dv = new DictValue();
dv.key = k1;
dv.value = v1;
listDict.Add(dv);
}
// 接下来,使用映射对象 listDict进行遍历
for (int i = 0; i < listDict.Count; i++)
{
Console.WriteLine("key:{0},value:{1}", listDict[i].key, listDict[i].value);
}
Console.ReadLine();
}
}
class DictValue
{
public string key="";
public string value="";
}
}
for (int i = 0; i < data.GetLength(); i++)
{
KeyValuePair<string, string> a = data[i];
}