I want to call the constructor of the structure, which has default values ββfor all parameters. But when I call the dimensionless constructor MyRectangle, an undefined constructor is called. Why is this? Is it possible not to have a constructor not created from me?
using System;
namespace UebungClasses
{
class Program
{
static void Main(string[] args)
{
MyRectangle sixRec = new MyRectangle(3, 2);
MyRectangle oneRec = new MyRectangle();
Console.WriteLine("area of six: " + sixRec.Area() + " area of one: " + oneRec.Area());
}
}
public struct MyRectangle
{
public MyRectangle(double w = 1, double l = 1)
{
width = w;
length = l;
Console.WriteLine("Width: " + width + " Lenght: " + length);
}
public double Area()
{
return width * length;
}
private double width;
private double length;
}
}
source
share