arrays - C# - Add to a static dictionary values locally -


i got code

static dictionary<string, xelement> dname = new dictionary<string, string> { }; static void main(string[] args)     {      dname.add("ro","fl");     } static void anothermethod(){ console.writeline(dname["ro"]); //not working, while in main works. }        

so how access other method?

dictionary dname shared among static , non-static methods of class. presence or absence of keys in dictionary depends on timing of insertion: if call

dname.add("ro","fl"); 

is made before call of anothermethod(), dname["ro"] should see value; if call of add made after, or key deleted before call of anothermethod(), lookup of "ro" going fail.

note passing data through static member variable fragile approach. better pass parameters explicitly - gives lot more control on pass:

static void anothermethod(idictionary<string,string>){     console.writeline(dname["ro"]); }    

Comments