title: Static string variable with complex initialization in C#
body: <p>I have a class with a static string variable that has a somewhat complex initialization (I can't just set it equal to a quoted string like <code>"whatever"</code>). I need to run a few lines of code to actually create the value. Once it gets set, its value won't change. It's currently set up as a property that just gets set on the first call to <code>get</code>.</p>
  
  <pre><code>class MyClass
  {
      private static string _myString = "";
      public static string MyString
      {
          get
          {
              if(_myString == "")
              {
                  // use an object "obj" here to create the value
                  MyObject obj = new MyObject();
                  obj.someSetupHere();
                  _myString = obj.ToString();
              }
              return _myString;
          }
      }
  }
  </code></pre>
  
  <p>My question is: is there a better way to do this? I would rather the value be set up when all the other variables get set, rather than on the first "get" of the value. Should I be using a <code>Lazy&lt;T&gt;</code> here instead? I would really like something like:</p>
  
  <pre><code>private static string _myString = 
  {
          // use an object "obj" here to create the value
          MyObject obj = new MyObject();
          obj.someSetupHere();
          _myString = obj.ToString();
  }
  </code></pre>
  
  <p>I know that's probably not valid syntax, but hopefully it conveys what I'm trying to do.</p>