Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The best overloaded method match has some invalid arguments

Tags:

c#

I can't get TryGetValue to work for some reason.

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?

like image 510
natli Avatar asked Mar 31 '12 16:03

natli


2 Answers

Add this line after creating the dictionary:

String value = "";
like image 56
NicoTek Avatar answered Sep 28 '22 07:09

NicoTek


It looks like the problem is that value isn'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 string or declare a new variable of type string to use in TryGetValue

like image 20
JaredPar Avatar answered Sep 28 '22 06:09

JaredPar