Dictionary<string, int> test = new Dictionary<string, int>();
test.Add("dave", 12);
test.Add("john", 14);
int v;
test.TryGetValue("dave", out int v)
{
Console.WriteLine(v);
}
这个简单的C#代码给出了“最佳重载方法匹配有一些无效参数”错误。你能告诉我错误的来源吗?谢谢。C#字典,这个简单代码中TryGetValue错误的来源是什么
您正在使用哪种版本的编译器?一旦我修复了语法错误,VS2017就喜欢那个代码。请发布完整,有效的示例代码,以便在某些特定的命名版本的编译器中可靠地重现问题。 –
'out int value'只有C#7 – haim770
你是否错过'test.TryGetValue'附近的if语句? –