एक शब्दकोश एक संदर्भ प्रकार है, तो यह मान द्वारा पारित करने के लिए संभव नहीं है, हालांकि एक शब्दकोश के लिए संदर्भ मूल्य हैं। मुझे इस स्पष्ट करने के लिए कोशिश करते हैं:
void Method1(Dictionary<string, string> dict) {
dict["a"] = "b";
dict = new Dictionary<string, string>();
}
void Method2(ref Dictionary<string, string> dict) {
dict["e"] = "f";
dict = new Dictionary<string, string>();
}
public void Main() {
var myDict = new Dictionary<string, string>();
myDict["c"] = "d";
Method1(myDict);
Console.Write(myDict["a"]); // b
Console.Write(myDict["c"]); // d
Method2(ref myDict); // replaced with new blank dictionary
Console.Write(myDict["a"]); // key runtime error
Console.Write(myDict["e"]); // key runtime error
}
[ पासिंग रेफरी द्वारा और बाहर] (http://stackoverflow.com/questions/1644372/passing-by-ref-and-out) इसी तरह के मुद्दों को शामिल किया गया। –