2012-03-31 12 views
9

何らかの理由で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 

誰もが私のコードで間違って何を教えてもらえますか?

+2

ここで、 'value'はどこに定義されていますか? –

+3

* value *はstring型の変数ではありません。私たちはそれを見ることができません。 –

答えて

8

で使用するタイプstringの新しい変数を宣言する必要があります:

String value = ""; 
+0

それは、ありがとう! – natli

2

valueは、stringに正しく入力されていないという問題があります。これが、あなたがその特定のエラーを起こす唯一の理由です。あなたはstringに値の種類を変更したり、辞書を作成した後、この行を追加しますTryGetValue

0

たぶん、このような何か:

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 
} 
関連する問題