C#字典的基本操作
这里是基本的字典操作,在添加字典的时候要注意KEY是否已经存在
定义:
Dictionary<string, string> dict= new Dictionary<string, string>();
添加:
if (dict.ContainsKey(stringKEY))
{
MessageBox.Show(string.Format("[{0}]已存在", stringKEY));
}
else
{
dict.Add(stringKEY, stringVALUE);
}删除
if (!dict.Remove(stringKEY))
{
MessageBox.Show(string.Format("未找到{0}项",stringKEY));
}查询:
MessageBox.Show(dict[stringKEY]);
遍历
foreach (var item in dict)
{
str += item.Key + "|" + item.Value +"\r\n";
}清空
dic.Clear();
扫描二维码推送至手机访问


