本文整理汇总了C#中Square.ComputeArea方法的典型用法代码示例。如果您正苦于以下问题:C# Square.ComputeArea方法的具体用法?C# Square.ComputeArea怎么用?C# Square.ComputeArea使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Square
的用法示例。
在下文中一共展示了Square.ComputeArea方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main(String[] args)
{
int input;
Console.WriteLine();
DisplayInfo();
input = Convert.ToInt32(Console.ReadLine());
while(input != 0)
{
switch(input)
{
case 1:
String shape = "Rectangle";
int tempH, tempW;
Console.WriteLine();
Console.Write("Enter the height of the rectangle: ");
tempH = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter the width of the rectangle: ");
tempW = Convert.ToInt32(Console.ReadLine());
Console.WriteLine();
Rectangle tempRectangle = new Rectangle(tempH, tempW);
Console.WriteLine("The shape is a: {0}", shape);
Console.WriteLine("The shape's height is: {0}", tempRectangle.Height);
Console.WriteLine("The shape's width is: {0}", tempRectangle.Width);
Console.WriteLine("The shape's area is: {0}", tempRectangle.ComputeArea());
break;
case 2:
String shape2 = "Square";
int tempH2;
Console.WriteLine();
Console.Write("Enter the height of the square: ");
tempH2 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine();
Square tempSquare = new Square(tempH2);
Console.WriteLine("The shape is a: {0}", shape2);
Console.WriteLine("The shape's height is: {0}", tempSquare.Height);
Console.WriteLine("The shape's width is: {0}", tempSquare.Width);
Console.WriteLine("The shape's area is: {0}", tempSquare.ComputeArea());
break;
case 3:
String shape3 = "Triangle";
int tempH3, tempW3;
Console.WriteLine();
Console.Write("Enter the height of the triangle: ");
tempH3 = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter the width of the triangle: ");
tempW3 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine();
Triangle tempTriangle = new Triangle(tempH3, tempW3);
Console.WriteLine("The shape is a: {0}", shape3);
Console.WriteLine("The shape's height is: {0}", tempTriangle.Height);
Console.WriteLine("The shape's width is: {0}", tempTriangle.Width);
Console.WriteLine("The shape's area is: {0}", tempTriangle.ComputeArea());
break;
}
Console.WriteLine();
DisplayInfo();
input = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine();
Console.WriteLine("Press the <Enter> key to terminate this program.");
Console.ReadLine();
}