Search code examples
c#graphicsinstances

C# infinite instances of a class


Can I create a virtually infinite number of instances of a class? Or can you tell me a better way to do this?

Here's my problem, I want to make a program that lets you create circles by clicking on the screen, they have to be displayed and to interact with one another. I'm pretty newbie, so I divided my project in some phases:

1 Display the form
2 Display circles on click with diameter and color chosen by the user
3 Make a separate class for single circles
4 Make them move
5 Make them interact with one another
6 Check for bugs etc.

I'm stuck between point 2 and 3. I'm not sure that making a Circle class and creating various instances is the smartest way to do this, but it's the only way I came up with that gave me the possibility to make infinite circles displayed. I could use an array, since I think no one will ever use more than 20 circles at a time. What's more, I don't even think I'll ever publish this, since I'm making this just to learn something of graphics. so, sooner or later, I'll need help with point 4.


Solution

  • I think you are looking for List. Its like an array in that it can contain items, but items can be added and removed at any point. So it can contain both 1 and 10000 items. Only limit is memory.