可以使用Dictionary类的ContainsKey方法来判断字典中是否存在指定的key。示例代码如下:

Dictionary<string, int> dict = new Dictionary<string, int>();
dict.Add("apple", 1);
dict.Add("banana", 2);

if (dict.ContainsKey("apple"))
{
    Console.WriteLine("字典中存在key为apple的项");
}
else
{
    Console.WriteLine("字典中不存在key为apple的项");
}

输出结果为:“字典中存在key为apple的项”。

c# 判断字典中是否存在key