title: Creating and Adding to a Dictionary in One Class, Accessing the Dictionary in Main Program
body: <p>In my C# code, I'm needing to create a Dictionary and Add entries to it in a particular class. Then, in my main program, I'm needing to check and see if my ID numbers I'm working with are in that Dictionary. I was imagining something simply like</p>
  
  <pre><code>public class Pref
  {
      public Dictionary&lt;string, string&gt; PreferredPartners =  new Dictionary&lt;string,string&gt;();
      PreferredPartners.Add("ID1part1" , "ID1part2");
      PreferredPartners.Add("ID2part1" , "ID2part2");
      . 
      .
      .
  }
  
  
  class Program
  {
      static void Main(string[] args)
      {
            .
            .
            .
            if(Pref.PreferedPartners.ContainsKey("someIDpart1"))
            {
                  do something;
            else
            {
                  do something else;
            }
            .
            .
            .
      }
  }
  </code></pre>
  
  <p>I've tried the above code but it doesn't like my "PreferredPartners.Add("","")" statement in the Pref class; saying that it's a field that's used like a type and that the () are invalid tokens. I thought doing it a separate class would still be identical to a "normal" ititialization in the main code. I tried looking at <a href="https://stackoverflow.com/questions/14304770/c-sharp-accessing-a-dictionary-from-another-class-is-not-working">C# Accessing a dictionary from another class is not working</a> for help but couldn't quite piece it together for my situation.</p>
  
  <p>How can I create this dictionary (and add to it) appropriately in my Pref class and how should my main program code read in order to let me check to see if certain ID's are in the Dictionary?</p>