当前位置: 首页>>代码示例>>C#>>正文


C# Rectangle.CalculateSurface方法代码示例

本文整理汇总了C#中Rectangle.CalculateSurface方法的典型用法代码示例。如果您正苦于以下问题:C# Rectangle.CalculateSurface方法的具体用法?C# Rectangle.CalculateSurface怎么用?C# Rectangle.CalculateSurface使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Rectangle的用法示例。


在下文中一共展示了Rectangle.CalculateSurface方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

    /*1.	Define abstract class Shape with only one abstract method CalculateSurface() and fields width and height.
        * Define two new classes Triangle and Rectangle that implement the virtual method and
        * return the surface of the figure (height*width for rectangle and height*width/2 for triangle).
        * Define class Circle and suitable constructor so that
        * on initialization height must be kept equal to width and implement the CalculateSurface() method.
        * Write a program that tests the behavior of  the CalculateSurface() method for different shapes (Circle, Rectangle, Triangle) stored in an array.*/
    static void Main()
    {
        Shape rectangle = new Rectangle(4.0, 5.5);
        Console.WriteLine("Surface of rectangle is: {0}", rectangle.CalculateSurface());

        Shape triangle = new Triangle(4.0, 5.5);
        Console.WriteLine("Surface of triangle is: {0}", triangle.CalculateSurface());

        Shape circle = new Circle(4.5);
        Console.WriteLine("Surface of circle is: {0:F6}", circle.CalculateSurface());

        Console.WriteLine();
        Console.WriteLine("---different shapes---");
        Shape[] shapes = {rectangle,
                            triangle,
                            circle,
                            new Circle(6.3),
                            new Triangle(4.6, 7.3)
                };

        foreach (var shape in shapes)
        {
            Console.WriteLine("Surface of {0} is {1}", shape.GetType(), shape.CalculateSurface());
        }
    }
开发者ID:ralikuman,项目名称:TelerikAcademy,代码行数:31,代码来源:ShapeExample.cs

示例2: Main

        public static void Main()
        {
            Circle circle = new Circle(5);
            Console.WriteLine(
                "I am a circle. " +
                "My perimeter is {0:f2}. My surface is {1:f2}.",
                circle.CalculatePerimeter(),
                circle.CalculateSurface());

            Rectangle rect = new Rectangle(2, 3);
            Console.WriteLine(
                "I am a rectangle. " +
                "My perimeter is {0:f2}. My surface is {1:f2}.",
                rect.CalculatePerimeter(),
                rect.CalculateSurface());
        }
开发者ID:Nezhdetov,项目名称:Software-University,代码行数:16,代码来源:FiguresExample.cs

示例3: Main

    static void Main()
    {
        Rectangle square = new Rectangle(5, 5);
        double sur = square.CalculateSurface();
        Console.WriteLine("We have square with '5' side,\nthe surface is {0} ", sur);

        Rectangle rec = new Rectangle(6.6, 9.3);
        double surface = rec.CalculateSurface();
        Console.WriteLine("\nWe have rectangle with '6.6' and '9.3' sides, \nthe surface is {0}", surface);

        Triangle trian = new Triangle(5.3,3.5);
        double sur3 = trian.CalculateSurface();
        Console.WriteLine("\nWe have triangle with base '5.3' and 3.5 height, \nthe surface is {0}", sur3);

        Circle cir = new Circle(7.4);
        double rad = cir.CalculateSurface();
        Console.WriteLine("\nWe have Circle with '7.4' raduis,\nthe surface is {0}", rad);
    }
开发者ID:joro1881,项目名称:CSharpProgramming,代码行数:18,代码来源:Program.cs

示例4: Main

    static void Main()
    {
        var rectangle = new Rectangle(4, 6);
        var area = rectangle.CalculateSurface();
        Console.WriteLine(area);
        var triangle = new Triangle(4, 3);
        var triangleArea = triangle.CalculateSurface();
        Console.WriteLine(triangleArea);
        //Throws an Exception
        //var circle = new Circle(2, 3);
        var circle = new Circle(3, 3);
        Console.WriteLine(circle.CalculateSurface());
        Console.WriteLine("\nAnd the same results using array: \n");
        Shape[] shapes = new Shape[3];
        shapes[0] = new Rectangle(4, 6);
        shapes[1] = new Triangle(4, 3);
        shapes[2] = new Circle(3, 3);

        foreach (var shape in shapes)
        {
            Console.WriteLine(shape.CalculateSurface());
        }
    }
开发者ID:bankoff,项目名称:TelerikAcademy,代码行数:23,代码来源:TestProgram.cs


注:本文中的Rectangle.CalculateSurface方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。