From aca44bc248734b3ef2df8147ac9ecec1826e037f Mon Sep 17 00:00:00 2001
From: Kister Hakusan <2753888203@qq.com>
Date: Thu, 11 Sep 2025 13:53:18 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0Lesson16?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
C#核心/C#核心.sln | 12 ++
.../Lesson16_继承-密封类.csproj | 11 ++
C#核心/Lesson16_继承-密封类/Program.cs | 34 ++++++
.../Lesson16_继承-密封类练习.csproj | 11 ++
C#核心/Lesson16_继承-密封类练习/Program.cs | 104 ++++++++++++++++++
5 files changed, 172 insertions(+)
create mode 100644 C#核心/Lesson16_继承-密封类/Lesson16_继承-密封类.csproj
create mode 100644 C#核心/Lesson16_继承-密封类/Program.cs
create mode 100644 C#核心/Lesson16_继承-密封类练习/Lesson16_继承-密封类练习.csproj
create mode 100644 C#核心/Lesson16_继承-密封类练习/Program.cs
diff --git a/C#核心/C#核心.sln b/C#核心/C#核心.sln
index 364e2dd..ec67d2d 100644
--- a/C#核心/C#核心.sln
+++ b/C#核心/C#核心.sln
@@ -27,6 +27,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson15_继承-万物之
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson15_继承-万物之父和装箱拆箱练习", "Lesson15_继承-万物之父和装箱拆箱练习\Lesson15_继承-万物之父和装箱拆箱练习.csproj", "{FD313E4D-09E3-4310-B001-8BD9BF0B7C45}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson16_继承-密封类", "Lesson16_继承-密封类\Lesson16_继承-密封类.csproj", "{C68D86B1-87E3-47FC-BF5B-B9B39E1B0BD1}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson16_继承-密封类练习", "Lesson16_继承-密封类练习\Lesson16_继承-密封类练习.csproj", "{673FABF2-99A7-4E63-B1F6-37AB53B6EC85}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -81,6 +85,14 @@ Global
{FD313E4D-09E3-4310-B001-8BD9BF0B7C45}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FD313E4D-09E3-4310-B001-8BD9BF0B7C45}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FD313E4D-09E3-4310-B001-8BD9BF0B7C45}.Release|Any CPU.Build.0 = Release|Any CPU
+ {C68D86B1-87E3-47FC-BF5B-B9B39E1B0BD1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {C68D86B1-87E3-47FC-BF5B-B9B39E1B0BD1}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {C68D86B1-87E3-47FC-BF5B-B9B39E1B0BD1}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {C68D86B1-87E3-47FC-BF5B-B9B39E1B0BD1}.Release|Any CPU.Build.0 = Release|Any CPU
+ {673FABF2-99A7-4E63-B1F6-37AB53B6EC85}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {673FABF2-99A7-4E63-B1F6-37AB53B6EC85}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {673FABF2-99A7-4E63-B1F6-37AB53B6EC85}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {673FABF2-99A7-4E63-B1F6-37AB53B6EC85}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/C#核心/Lesson16_继承-密封类/Lesson16_继承-密封类.csproj b/C#核心/Lesson16_继承-密封类/Lesson16_继承-密封类.csproj
new file mode 100644
index 0000000..72b5ea5
--- /dev/null
+++ b/C#核心/Lesson16_继承-密封类/Lesson16_继承-密封类.csproj
@@ -0,0 +1,11 @@
+
+
+
+ Exe
+ net8.0
+ Lesson16_继承_密封类
+ enable
+ enable
+
+
+
diff --git a/C#核心/Lesson16_继承-密封类/Program.cs b/C#核心/Lesson16_继承-密封类/Program.cs
new file mode 100644
index 0000000..bbe4670
--- /dev/null
+++ b/C#核心/Lesson16_继承-密封类/Program.cs
@@ -0,0 +1,34 @@
+namespace Lesson16_继承_密封类
+{
+
+ #region 知识点一 基本概念
+ //密封类 是使用 sealed密封关键字修饰的类
+ //作用:让类无法再被继承
+ #endregion
+
+ #region 知识点二 实例
+ class Father
+ {
+
+ }
+
+ sealed class Son : Father//之后无法再被继承
+ {
+
+ }
+ #endregion
+
+ #region 知识点三 作用
+ //在目前的程序设计中,密封类的主要作用就是不允许最底层子类被继承
+ //可以保证程序的规范性
+ //目前对于我们来说 可能用处不大
+ #endregion
+
+ internal class Program
+ {
+ static void Main(string[] args)
+ {
+ Console.WriteLine("Hello, World!");
+ }
+ }
+}
diff --git a/C#核心/Lesson16_继承-密封类练习/Lesson16_继承-密封类练习.csproj b/C#核心/Lesson16_继承-密封类练习/Lesson16_继承-密封类练习.csproj
new file mode 100644
index 0000000..110059d
--- /dev/null
+++ b/C#核心/Lesson16_继承-密封类练习/Lesson16_继承-密封类练习.csproj
@@ -0,0 +1,11 @@
+
+
+
+ Exe
+ net8.0
+ Lesson16_继承_密封类练习
+ enable
+ enable
+
+
+
diff --git a/C#核心/Lesson16_继承-密封类练习/Program.cs b/C#核心/Lesson16_继承-密封类练习/Program.cs
new file mode 100644
index 0000000..4cbc88d
--- /dev/null
+++ b/C#核心/Lesson16_继承-密封类练习/Program.cs
@@ -0,0 +1,104 @@
+namespace Lesson16_继承_密封类练习
+{
+ class Vehicle
+ {
+ public int speed;
+ public int maxSpeed;
+ public int maxCapacity;
+ public int nowMemberindex;
+
+ public Human[] passenger;
+
+ public Vehicle(int speed, int maxSpeed, int maxCapacity)
+ {
+ this.speed = speed;
+ this.maxSpeed = maxSpeed;
+ this.nowMemberindex = 0;
+ this.maxCapacity = maxCapacity;
+ passenger = new Human[maxCapacity];
+ }
+
+ public void GetOn(Human p)
+ {
+ if (nowMemberindex >= maxCapacity)
+ {
+ Console.WriteLine("乘客已满");
+ return;
+ }
+ else
+ {
+ Console.WriteLine("已上车");
+ passenger[nowMemberindex] = p;
+ nowMemberindex++;
+ }
+
+ }
+
+ public void GetOff(Human p)
+ {
+ for (int i = 0; i < nowMemberindex; i++)
+ {
+ if (passenger[i] == p)
+ {
+ for (int j = i; j < nowMemberindex - 1; j++)
+ {
+ passenger[j] = passenger[j + 1];
+ }
+ passenger[nowMemberindex - 1] = null;
+ nowMemberindex--;
+ Console.WriteLine("已下车一位成员");
+ break;
+ }
+ }
+ }
+
+ public void Moving()
+ {
+
+ }
+
+ public void Accident()
+ {
+
+ }
+ }
+ class Human
+ {
+
+ }
+ class Driver : Human
+ {
+
+ }
+ class Passenger : Human
+ {
+ public int age;
+ public string name;
+ public Passenger()
+ {
+
+ }
+ public Passenger(int age,string name)
+ {
+ this.age = age;
+ this.name = name;
+ }
+ }
+ internal class Program
+ {
+ static void Main(string[] args)
+ {
+ Console.WriteLine("Hello, World!");
+ Human h1 = new Passenger(1,"h1");
+ Human h2 = new Passenger(2,"h2");
+ Human h3 = new Passenger(3,"h3");
+ Vehicle Car = new Vehicle(20,200,2);
+ Car.GetOn(h1);
+ Car.GetOn(h2);
+ Car.GetOn(h3);
+ Car.GetOff(h1);
+ Car.GetOn(h3);
+ Car.GetOff(h3);
+ }
+ }
+}