title: Creating objects within a loop
body: <p>I have been searching about creating a new object within a loop, found some answers and topics but its way too hard to understand. Making it with lists and arrays etc.</p>
  
  <p>What I am trying to do is, get an input from the user(lets say 3), and create objects as many as the user will with the unique names. Like newperson1, newperson2, newperson3 etc.</p>
  
  <p>My code looks like this:</p>
  
  <pre><code>class person
  {
  }
  
  class Program
  {
      static void Main(string[] args)
      {
          Console.Write("How many persons you want to add?: ");
          int p = int.Parse(Console.ReadLine());
  
          for (int i = 0; i &lt; p; i++)
          {
              person newperson = new person();
          }
      }
  }
  </code></pre>
  
  <p>Is there any way to create new objects with following numbers in the end of the object name?
  Thanks!</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>My new code looks like this; I was more thinking like this:</p>
  
  <pre><code>class Persons
  {
      //Person object id
      public int id { get; set; }
  
      //Persons name
      public string name { get; set; }
  
      //Persons adress
      public string adress { get; set; }     
  
      //Persons age
      public int age { get; set; }
  
      }
  
  class Program
  {
      static void Main(string[] args)
      {
          Console.Write("How many persons you want to add?: ");
          int count = int.Parse(Console.ReadLine());
  
          var newPersons = new List&lt;Persons&gt;(count);
  
          for (int i = 0; i &lt; count; i++)
          {
              newPersons[i].id = i;
  
              Console.Write("Write name for person " + i);
              newPersons[i].name = Console.ReadLine();
  
              Console.Write("Write age for person " + i);
              newPersons[i].age = int.Parse(Console.ReadLine());
  
              Console.Write("Write adress for person " + i );
              newPersons[i].adress = Console.ReadLine();
  
          }
  
          Console.WriteLine("\nPersons \tName \tAge \tAdress");
          for (int i = 0; i &lt; count; i++)
          {
              Console.WriteLine("\t" + newPersons[i].name + "\t" + newPersons[i].age + "\t" + newPersons[i].adress);
          }
  
          Console.ReadKey();
      }
  }
  </code></pre>
  
  <p>I understand that I have to create object with arrays or lists. But I didn't really understand how I will access them after they are created person by person.. </p>