James Webb

James Webb

  • NA
  • 11
  • 9.6k

Creating Objects

Jun 28 2014 1:00 PM
Hi all,
 
I'm still very new  with C# and I have just started to get my head round objects.
What I would like to know is how would I program a way of making any number of objects and give each object a name like "Person_1" and "Person_2".
Is this even possible? I have tried the following but it doesn't work:
 
 for (int i = 0; i < count; i++)
{
Player ("Player_" + i) = new Player();
}
 
Is there a better way to go about doing this? The big picture (if its any use) is my program reading from a text file using streamreader and creating an object every 6 lines (my object has 6 parameters). There will be a maximum of around 100 objects so I really would like a much more efficient way of creating these objects.
 
Many Thanks and Kind Regards,
James Webb 
 
P.S. Please remember I'm a beginner, try to keep it as simple as possible and explain as much as you can, it would be very much appreciated! 

Answers (1)