If i want to declare an array of same objects(I mean same constructor paramter values). can i do it in one shot.
In the below example If i want to create 4 box objects with same dimensions (3, 3, 2), I called the constructor 4 times. Can i do this in one shot?
class Program
{
static void Main(string[] args)
{
Box b = new Box(3, 4, 7);
Console.WriteLine(b.getVolume());
Box[] matchBoxes = new Box[4];
matchBoxes[0] = new Box(3, 3, 2);
matchBoxes[1] = new Box(3, 3, 2);
matchBoxes[2] = new Box(3, 3, 2);
matchBoxes[3] = new Box(3, 3, 2);
Console.ReadLine();
}
}
class Box
{
private int length;
private int breadth;
private int height;
public Box(int l, int b, int h)
{
this.length = l;
this.breadth = b;
this.height = h;
}
public int getVolume()
{
return (this.length*this.breadth*this.height);
}
}