Synchronization of old projects
Part1
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<RootNamespace>Lesson8_封装_静态类和静态构造函数练习</RootNamespace>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,48 @@
|
||||
namespace Lesson8_封装_静态类和静态构造函数练习
|
||||
{
|
||||
static class Calc
|
||||
{
|
||||
private static float PI = 3.1415926f;
|
||||
public static float CalcCirclePerimeter(int r)
|
||||
{
|
||||
return PI * r * 2;
|
||||
}
|
||||
public static float CalcCircleArea(int r)
|
||||
{
|
||||
return PI * r * r;
|
||||
}
|
||||
public static int CalcRectanglePerimeter(int h,int w)
|
||||
{
|
||||
return (h + w) * 2;
|
||||
}
|
||||
public static int CalcRectangleArea(int h, int w)
|
||||
{
|
||||
return h * w;
|
||||
}
|
||||
public static int Absolute(int num)
|
||||
{
|
||||
if (num < 0)
|
||||
{
|
||||
return -num;
|
||||
}
|
||||
else
|
||||
{
|
||||
return num;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("Hello, World!");
|
||||
Console.WriteLine(Calc.CalcRectanglePerimeter(5,10));
|
||||
Console.WriteLine(Calc.CalcRectangleArea(5, 10));
|
||||
Console.WriteLine(Calc.CalcCirclePerimeter(3));
|
||||
Console.WriteLine(Calc.CalcCircleArea(3));
|
||||
Console.WriteLine(Calc.Absolute(123));
|
||||
Console.WriteLine(Calc.Absolute(-321));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user