7
Reply

initializing and accessing dictionary globally

rohit pol

rohit pol

Apr 21 2012 11:12 PM
5.8k
Hi All,

I am loading Dictionary object with some values and wanted to access it throughout my project, how can I do that. Please see explained below.

public class class1{
 class2 cl2 = new class2();
 cl2.loadDataFile();
}

public class class3{
  string str = "______________________"; 
  class2 cls2 = new class2();
 cls2.getStrings(str);
}

public class class2{
  protected Dictionary<string, string> store =
  new Dictionary<string, string>();
  public void loadDataFile()
 {
  //logic to load data from file on certain
  //conditions and store it in 'store' Dictionary
  object declared above.
 }
 public string getStrings(sring str)
  {
  //Here I will access elements of 'store'.
  //I get '0' element. How to get elements here.
  }
}

Thanks,

Answers (7)