Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add("1", "11");
dic.Add("2", "12");
dic.Add("3", "13");
dic.Add("4", "14");
dic.Add("5", "15");
dic.Add("6", "16");
//****************************************
string[] keys = new string[dic.Keys.Count];
dic.Keys.CopyTo(keys, 0);
foreach (string key in keys)
{
if (key != "4")
dic.Remove(key);
}
//****************************************
Console.WriteLine(dic.Count.ToString());
转载于:https://www.cnblogs.com/HaifengCai/p/3629782.html