本文整理汇总了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());
}
示例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;
}
}