C# 最佳重载方法匹配有一些无效参数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9957459/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The best overloaded method match has some invalid arguments
提问by natli
I can't get TryGetValueto work for some reason.
TryGetValue由于某种原因,我无法上班。
Dictionary<String,String> testdict = new Dictionary<String,String>();
String teststr = "test";
if(testdict.TryGetValue(teststr,out value))
{
//Ladida
}
Error received:
收到错误:
The best overloaded method match for 'System.Collections.Generic.Dictionary<string,string>.TryGetValue(string, out string)' has some invalid arguments
Can anyone tell me what's wrong with my code?
谁能告诉我我的代码有什么问题?
采纳答案by NicoTek
Add this line after creating the dictionary:
创建字典后添加此行:
String value = "";
回答by JaredPar
It looks like the problem is that valueisn't properly typed to string. This is the only reason that you would get that particular error. You need to change the type of value to stringor declare a new variable of type stringto use in TryGetValue
看起来问题在于value没有正确输入string. 这是您会收到该特定错误的唯一原因。您需要将值的类型更改为string或声明string要使用的新类型变量TryGetValue
回答by Arion
Maybe something like this:
也许是这样的:
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
}

