title: C# static and non-static string variables in a formatted string as parameters
body: <p>As a newbie in C#, I am trying to figure out why I have to put <code>CardNumber</code> as such as static in order to fit into the formatted string.... </p>
  
  <p>If I didn't add <code>static string CardNumber</code> but use <code>string CardNumber;</code>, the code would report an error with the last <code>CardNumber</code> underlined. The error goes: <strong>A field initializer cannot reference the non-static field, method, or property 'WriteXML.CardNumber'</strong>. </p>
  
  <p>I know there are tons of static and non-static comments and questions out there. None of them seems to directly explain, "if using non-static in a formatted string, then <strong>_ will happen, or then _</strong> won't make any sense". If duplicate, please kindly point out the resource at least. I really appreciate it!</p>
  
  <pre><code>class WriteXML
  {
      static string CardNumber;
      static string ExpMo;
      static string ExpYr;
      static string FirstName;
      static string LastName;
      string xmlContent =
          string.Format("&lt;CardNumber&gt;{0}&lt;/CardNumber&gt;" +
          "&lt;ExpMo&gt;{1}&lt;/ExpMo&gt;" +
          "&lt;ExpYr&gt;{2}&lt;/ExpYr&gt;" +
          "&lt;FirstName&gt;{3}&lt;/FirstName&gt;" +
          "&lt;LastName&gt;{4}&lt;/LastName&gt;", 
              CardNumber, ExpMo, ExpYr, FirstName, LastName);
  }
  </code></pre>