title: How to use class fields inside new statement using initializer syntax
body: <p>I have a class that I would like to instantiate. It contains two fields, one is a String, and the other is a Action. </p>
  
  <p>Within the action statement, I would like to use the string field in my class. However, I do not know how to directly call it while instantiating. Is there any way, or will I have to create a field to contain the instantiated class, and then call text?</p>
  
  <pre><code>public class ExampleClass
  {
      public string text;
      public Action action;
      // on class instantiate -&gt; action.Invoke();
  }
  
  public class Program
  {
      static void Main(string[] args)
      {
          new ExampleClass
          {
              text = "Hello",
              action = () =&gt; { 
                   /* use the text element we specified to do something -&gt; 
                      e.g Console.WriteLine(text); */ },
          };
          Console.ReadLine();
      }
  }
  </code></pre>
  
  <p>Trying to just use <code>text</code> field (like <code>action =&gt; ()=&gt; {Console.WriteLine(text);}</code>) results in error:</p>
  
  <blockquote>
    <p>CS0103  The name 'text' does not exist in the current context</p>
  </blockquote>