title: C# reading variables into static string from text file
body: <p>I have seen several posts giving examples of how to read from text files, and examples on how to make a string 'public' (static or const), but I haven't been able to combine the two inside a 'function' in a way that is making sense to me.</p>
  
  <p>I have a text file called 'MyConfig.txt'.
  In that, I have 2 lines.</p>
  
  <pre><code> MyPathOne=C:\TestOne
   MyPathTwo=C:\TestTwo
  </code></pre>
  
  <p>I want to be able to read that file when I start the form, making both MyPathOne and MyPathTwo accessible from anywhere inside the form, using something like this :</p>
  
  <pre><code>ReadConfig("MyConfig.txt");
  </code></pre>
  
  <p>the way I am trying to do that now, which is not working, is this :</p>
  
  <pre><code>public voice ReadConfig(string txtFile)
  {
      using (StreamReader sr = new StreamResder(txtFile))
      {
          string line;
          while ((line = sr.ReadLine()) !=null)
          {
              var dict = File.ReadAllLines(txtFile)
                             .Select(l =&gt; l.Split(new[] { '=' }))
                             .ToDictionary( s =&gt; s[0].Trim(), s =&gt; s[1].Trim());
          }
          public const string MyPath1 = dic["MyPathOne"];
          public const string MyPath2 = dic["MyPathTwo"];
      }
  }
  </code></pre>
  
  <p>The txt file will probably never grow over 5 or 6 lines, and I am not stuck on using StreamReader or  dictionary. </p>
  
  <p>As long as I can access the path variables by name from anywhere, and it doesn't add like 400 lines of code or something , then I am OK with doing whatever would be best, safest, fastest, easiest.</p>
  
  <p>I have read many posts where people say the data should stored in XML, but I figure that part really doesn't matter so much because reading the file and getting the variables part would be almost the same either way. That aside, I would rather be able to use a plain txt file that somebody (end user) could edit without having to understand XML. (which means of course lots of checks for blank lines, does the path exist, etc...I am OK with doing that part, just wanna get this part working first).</p>
  
  <p>I have read about different ways using ReadAllLines into an array, and some say to create a new separate 'class' file (which I don't really understand yet..but working on it). Mainly I want to find a 'stable' way to do this.
  (project is using .Net4 and Linq by the way)</p>
  
  <p>Thanks!!</p>