Create instance on class programatically
what is the correct procedure to automate instantiation of a class ?
if i create a class
Code:
class animal()
{
int age { get; set; } // private by default
int weight { get; set; }
int counter { get; set; }
public animal() //default constructor
{
age = 20;
weight = 10;
}
public void set_age(int new_age)
{
age = new_age;
}
public void set_weight(int new_weight)
{
weight = new_weight;
}
now i want to create an infinite number of animals in my code.
i figure it has to use an array to track objects
animal[i].set_age(int 30);
animal[i].set_weight(int 40);
but how do i implement this so i instantiate a new animal anywhere and the class will increment its index and create it ( and keep count so i can check) ?
i have seen this somewhere but think i lost the link :(
cheers