Home > Net >  Write a rectangle class, on the basis of defining a rectangle class, use based on the rectangle with
Write a rectangle class, on the basis of defining a rectangle class, use based on the rectangle with

Time:12-10

using System;

The namespace rectangle class
{
//rectangle class
Public class Rectangle
{
Private float width;
Private float height;
Private float chang;
//: constructor argument for the width of the width and height is the height and long chang
Public Rectangle (float width, float height, float chang)
{
This. Width=width;
This. Height=height;
This. Chang=chang;
}
//get width
Public float Width {get {return this. Width; }}
//get highly
Public float Height {get {return this. Height; }}
//get length
Public float Chang {get {return this. Chang; }}
//get the rectangular area
Public float Area {get {return this. Width. * this height. }}
//get the perimeter
Public float Circumference {get {return 2 * (. This. This width + height); }}
//get rectangle size
Public float Volume {get {return this. Chang. * this height. * this width; }}
//get the rectangle area
Public float Bmj {get {return 2 * (enclosing height. * this width) + 2 * (enclosing width * this. Chang) + 2 * (this. Chang. * this height); }}
//output
Public override string ToString ()
{
Return the string. Format (" the width of the rectangle: {0}, height: {1}, wide: {2}, rectangular area: {3}, rectangular circumference: {4}, a rectangular volume: {5}, rectangle area: {6} ",
Width, Height, Chang, Area, Circumference, Volume, Bmj);
}

}
Class Program
{
The static void Main (string [] args)
{
A Rectangle r1=new Rectangle (5, 7, 9); Long/wide/high
Console. WriteLine (r1. The ToString ());
Console.ReadLine();
}
}
  •  Tags:  
  • C#
  • Related