title: How to return an array of objects in c#
body: <p>I have two classes,  Program(main class) and Driver.What I am trying to do is allow the user to create a Driver through the command line however I can't seem to get the array to print out. I am new to c# and programming not certain that this is the best way around this so any ideas help. thanks</p>
  
  <p>Main Class</p>
  
  <pre><code>public class Program    
  {           
      static void Main(string[] args)
      {
          List&lt;Driver&gt; MyDriver = new List&lt;Driver&gt;();
          for (var a = 0; a &lt; 5; a++)
          {    
              Driver driver = new Driver();                   
              Console.WriteLine("Enter the Drivers Name");
              string driverName = driver.Name(Console.ReadLine());    
              Console.WriteLine("Enter the Drivers Occupation");
              string driverOccupation = driver.Occupation(Console.ReadLine());
              Console.WriteLine("How many claims does this driver have?");                 
              int noOfClaims = driver.Claim(int.Parse(Console.ReadLine()));                    
              Console.WriteLine("Your car details: \n " + driverName + " \n " + driverOccupation + "\n " + noOfClaims);    
              MyDriver.Add(new Driver());                  
          }
  
          foreach (Driver i in MyDriver)
          {
              Console.WriteLine(" Driver Details  " + MyDriver);
          }
  
          // Keep the console window open in debug mode.
          Console.WriteLine("Press any key to exit.");
          Console.ReadKey();
      }
  
  }
  </code></pre>
  
  <p>Driver Class</p>
  
  <pre><code>public class Driver  
  {
      //Properties
      private string driverName; 
      private string driverOccupation;  
      private DateTime driverDOB; 
      private DateTime claimDate;  
      private int noOfClaims;  
  
      public Driver()//Default Constructor
      {
          driverName = "";
          driverOccupation = "";
          driverDOB = DateTime.MinValue;// Default value 01/01/0001
          claimDate = DateTime.MinValue;// Default value
          noOfClaims = 0;  
      }
  
      public Driver(string name , string occupation , DateTime dateOfBirth , DateTime dateOfClaim, int claims)
      {
          driverName = name;
          driverOccupation = occupation;
          driverDOB = dateOfBirth;
          claimDate = dateOfClaim;
          noOfClaims = claims;
      }
  
      public string Name(string driverName)
      {
          return driverName;
      }
  
      public string Occupation (string driverOccupation)
      {
          return driverOccupation;         
      }
  
      public DateTime DateOfBirth(DateTime driverDOB) 
      {
          return driverDOB;       
      }
  
      public int Claim(int noOfClaims) 
      { 
          return noOfClaims;     
      }
  
      public override string ToString()
      {
          return String.Format(driverName , driverOccupation , driverDOB , noOfClaims );
      }
  }
  </code></pre>