C#题目:

2025-04-28 05:34:28
推荐回答(1个)
回答1:

我直接给你写出来:

//长方形类
     public class Rectangle
     {
         //长
         private int length;

         public int Length
         {
             get { return length; }
             set { length = value; }
         }

         //宽
         private int width;

         public int Width
         {
             get { return width; }
             set { width = value; }
         }

         //坐标x
         private double coordX;

         public double CoordX
         {
             get { return coordX; }
             set { coordX = value; }
         }
         //坐标y
         private double coordY;

         public double CoordY
         {
             get { return coordY; }
             set { coordY = value; }
         }
         public Rectangle(int length, int width, double coordX, double coordY)
         {
             this.length = length;
             this.width = width;
             this.coordX = coordX;
             this.coordY = coordY;
         }

         public void Print()
         {
             Console.WriteLine("长:{0},宽:{1},X坐标:{2},Y坐标{3}", this.length, this.width, this.coordX, this.coordY);
         }
     }

调用如下:

            Rectangle rec = new Rectangle(6, 2, 6.6, 8.8);
            rec.Print();