title: Initializing nested object properties
body: <p>I have a class called employee which has a field called insurance which is of type insurance like this</p>
  
  <pre><code>public class Employee
  {
      public string Name;
      public Insurance Insurance;
  }
  </code></pre>
  
  <p>I have another class called Insurance</p>
  
  <pre><code>public class Insurance
  {
      public int PolicyId;
      public String PolicyName;
  } 
  </code></pre>
  
  <p>Now in the main program i want to do something like</p>
  
  <pre><code>var myEmployee = new Employee();
  myEmployee.Name = "Jhon";
  myEmployee.Insurance.PolicyId = 123 ;
  myEmployee.Insurance.PolicyName = "Life Time" ;
  </code></pre>
  
  <p>C# is complaining and i know how to fix it by creating a instance of the Insurance class.</p>
  
  <p>My question is can i somehow assign the values for the fields in the way i want to do it in the main program using like                       </p>
  
  <p>**</p>
  
  <pre><code>myEmployee.Insurance.PolicyId = 123 ;
  myEmployee.Insurance.PolicyName = "Life Time" ;
  </code></pre>
  
  <p>**
  I tried</p>
  
  <pre><code> public class Employee
      {
  
          public Employee()
          {
              Insurance Insurance = new Insurance();
          }
  
          public String Name;
          public Insurance Insurance;
  
  
  
          public class Insurance
          {
              public int PolicyId;
              public String PolicyName;
          } 
      }
  </code></pre>
  
  <p>In the main method when i try</p>
  
  <pre><code>class Program
      {
          static void Main(string[] args)
          {
              var joe = new Employee();
              joe.Name = "Joe";
              joe.Insurance.
  
          }
  </code></pre>
  
  <p>I get this error-</p>
  
  <p><strong>Error 2   Ambiguity between 'ConsoleApplication1.Employee.Insurance' and 'ConsoleApplication1.Employee.Insurance' c:\users\lenovo\documents\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs    15  17  ConsoleApplication1</strong></p>