1. 定义字典变量,并初始化
// 元素值字典
Dictionary<string, string> dic = new Dictionary<string, string>()
{
{ "名称",""},
{"描述1",""},
{"拆分2",""}
}
2.清空字典值,保留键
Dictionary<string, string>.KeyCollection keys = dic.Keys;
String[] s = keys.ToArray<string>();
foreach (string a in s)
{
dic[a] = "";
}
不能直接用foreach循环,直接改变dic值,因为foreach是只读的。