我想调用一个结构的构造函数,它具有所有参数的默认值。但是当我调用 MyRectangle 的无参数构造函数时,会调用一个未定义的构造函数。这是为什么?是否可以不调用 not 从我创建的构造函数?
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()
{ …Run Code Online (Sandbox Code Playgroud)