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


C# Circle.CalcSurface方法代码示例

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


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

示例1: Main

 private 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.CalcPerimeter(),
         circle.CalcSurface());
     Rectangle rect = new Rectangle(2, 3);
     Console.WriteLine(
         "I am a rectangle. " + "My perimeter is {0:f2}. My surface is {1:f2}.",
         rect.CalcPerimeter(),
         rect.CalcSurface());
 }
开发者ID:i-yotov,项目名称:Courses,代码行数:13,代码来源:FiguresMain.cs

示例2: Main

    public static void Main()
    {
        // Dostapvat se pot toci nachin, tai kato klasovete sa bez constructori s parametri, a samo s propertita
        // Moje da se dostapi i s konstructor bez parametri:
        var c = new Circle();
        c.Radius = 3;

        // Tova savpada s:
        var d = new Circle { Radius = 3 };
        Console.WriteLine(c.CalcSurface());

        // Moje da se zapishe i taka:
        // Figure e=new Circle();// no niama da moga da dostapia radiusa, tai kato toi ne e definiran vav Figure
        // Moje dori da definirame obekt i kato Interface, no te imame dostap samo do metodite v interfaca
        Figure[] figures =
            {
                new Square { Size = 3 }, new Circle { Radius = 2 }, new Rectangle { Width = 2, Height = 3 },
                new Circle { Radius = 3.5 }, new Square { Size = 2.5 }, new Square { Size = 4 }
            };

        foreach (var figure in figures)
        {
            Console.WriteLine(
                "Figure = {0} surface = {1:F2}",
                figure.GetType().Name.PadRight(10, ' '),
                figure.CalcSurface());
        }

        foreach (var figure in figures)
        {
            Console.WriteLine(figure.ToString()); // override sme ToString samo v Square
        }

        var circles = figures.Where(fig => fig is Circle).Cast<Circle>();

        // is ste hvane i naslednicite na Circle, ako ima takiva, primerno SpecialCircle, no kolekciata vse oste e ot figuri, i zatova go castvame
        foreach (var circle in circles)
        {
            // Moje i tuka da se castne, kato vmesto var se napishe Circle vav foreacha
            //Ako ne e castvano moje i tuka da se castva s var c1=circle as Circle;//operatora az varshi i proverka i kastvane(po-dobrar ot is), ako ne moje da go castne vrasta null
            circle.Radius = 5;
        }
    }
开发者ID:EBojilova,项目名称:CSharp-OOP-June-2015,代码行数:43,代码来源:Polymorphism.cs


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