最佳重载方法匹配包含一些无效参数
本文关键字:无效 参数 包含一 重载 方法 最佳 | 更新日期: 2023-09-27 18:29:40
由于某种原因,我无法使TryGetValue
工作。
Dictionary<String,String> testdict = new Dictionary<String,String>();
String teststr = "test";
if(testdict.TryGetValue(teststr,out value))
{
//Ladida
}
收到错误:
The best overloaded method match for 'System.Collections.Generic.Dictionary<string,string>.TryGetValue(string, out string)' has some invalid arguments
有人能告诉我我的代码出了什么问题吗?
在创建字典后添加此行:
String value = "";
问题似乎是value
没有正确键入为string
。这是你会得到那个特定错误的唯一原因。您需要将值的类型更改为string
或声明一个类型为string
的新变量以在TryGetValue
中使用
也许是这样的:
Dictionary<String,String> testdict = new Dictionary<String,String>();
string theValueYouAreTryingFor = "test";
string theValueYourGetting;
if(testdict.TryGetValue(theValueYouAreTryingFor,out theValueYourGetting))
{
//If the value is in the Dictionary
}