title: A field initializer cannot reference the non-static field, method, or property?
body: <p>I have a Repository Class and a Services Class as below :</p>
  
  <pre><code>public class DinnerRepository
  {
      DinnerDataContext db = new DinnerDataContext();
  
      public Dinner GetDinner(int id)
      {
          return db.Dinners.SingleOrDefault(d =&gt; d.DinnerID == id);   
      }
  
  // Others Code        
  }
  
  
  
  public class Service
  {
          DinnerRepository repo = new DinnerRepository(); 
          Dinner dinner = repo.GetDinner(5);
  
  // Other Code
  }
  </code></pre>
  
  <p>This throws error:</p>
  
  <blockquote>
    <p>A field initializer cannot reference the non-static field, method, or property.</p>
  </blockquote>
  
  <p>Even though I have intatiated the DinnerRepository Class to expose its method GetDinner() in the Service Class. This works fine with below code. Is there any alternative to it or is it a standard practice? I cannot use static methods here..</p>
  
  <pre><code>public class Service
  {
  
      public Service()
      {
          DinnerRepository repo = new DinnerRepository(); 
          Dinner dinner = repo.GetDinner(5);
      }
  
  }
  </code></pre>