2012-03-31 7 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

ऐसा लगता है कि * वैल्यू * प्रकार स्ट्रिंग का चर नहीं है। हम इसे नहीं देख सकते हैं। –

उत्तर

8

में उपयोग करने के लिए string को मान का प्रकार बदलने के लिए या प्रकार string का एक नया चर घोषित करने के लिए की जरूरत है शब्दकोश बनाने के बाद इस लाइन जोड़ें:

String value = ""; 
+0

उसने ऐसा किया, धन्यवाद! – natli

2

ऐसा लगता है कि समस्या यह है कि value ठीक से 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 
} 
संबंधित मुद्दे