Archived
1
0
This commit is contained in:
2025-11-15 20:25:57 +08:00
Unverified
parent 5478d0ed37
commit bb4a37acc4
99 changed files with 4315 additions and 16 deletions

11
cs5/5_4/5_4.csproj Normal file
View File

@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>_5_4</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

25
cs5/5_4/5_4.sln Normal file
View File

@@ -0,0 +1,25 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36616.10 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "5_4", "5_4.csproj", "{43F29EB3-99B5-4064-911E-3B3570272923}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{43F29EB3-99B5-4064-911E-3B3570272923}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{43F29EB3-99B5-4064-911E-3B3570272923}.Debug|Any CPU.Build.0 = Debug|Any CPU
{43F29EB3-99B5-4064-911E-3B3570272923}.Release|Any CPU.ActiveCfg = Release|Any CPU
{43F29EB3-99B5-4064-911E-3B3570272923}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {20D2A0A1-A7D4-4CAC-BC03-AACF2D5F63B0}
EndGlobalSection
EndGlobal

60
cs5/5_4/Program.cs Normal file
View File

@@ -0,0 +1,60 @@
namespace _5_4
{
public abstract class Shape
{
protected string name;
public Shape(string name)
{
this.name = name;
}
public abstract void Show();
public abstract double Area();
}
public class Rectangle : Shape
{
protected double width;
protected double height;
public Rectangle(string name, double width, double height) : base(name)
{
this.width = width;
this.height = height;
}
public override void Show()
{
Console.WriteLine("Rectangle: {0} , area :{1}", name, width * height);
}
public override double Area()
{
return width * height;
}
}
public class Circle : Shape
{
protected double radius;
public Circle(string name, double radius) : base(name)
{
this.radius = radius;
}
public override void Show()
{
Console.WriteLine("Circle: {0} , area :{1}", name, Math.PI * radius * radius);
}
public override double Area()
{
return Math.PI * radius * radius;
}
}
public class Program
{
static void Main(string[] args)
{
Shape[] s = { new Rectangle("小矩形",1.0,2.0),
new Circle("大源",5.0),
};
foreach (Shape shape in s)
{
shape.Show();
}
}
}
}