Synchronization of old projects

Part1
This commit is contained in:
2025-09-30 16:46:01 +08:00
parent 116b65164b
commit 4e1548abe2
167 changed files with 8668 additions and 43 deletions
@@ -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,125 @@
namespace Lesson8
{
#region
class
{
#region
#endregion
#region
#endregion
#region
#endregion
#region
#endregion
#region
#endregion
#region
#endregion
#region
#endregion
}
#endregion
#region
//概念
//用static修饰的类
//特点
//只能包含静态成员
//不能被实例化
//作用
//1.将常用的静态成员写在静态类中 方便使用
//2.静态类不能被实例化,更能体现工具类的 唯一性
//比如 consle就是一个静态类
static class Tools
{
public static int testIndex = 0;//静态成员变量
public static void TestFun() { }
public static int TestIndex
{
get { return testIndex; }
set { testIndex = value; }
}
}
#endregion
#region
//概念
//在构造函数加上 static 修饰
//特点
//1.静态类和普通类都可以有
//2.不能使用访问修饰符
//3.不能有参数
//4.只会自动调用依次
//作用
//在静态构造函数中初始化
//1.静态类中的静态构造函数
static class StaticClass
{
public static int testInt = 100;
public static int testInt2 = 200;
public static int testInt3;
static StaticClass()
{
Console.WriteLine("静态构造函数");
testInt3 = 300;
}
}
//2.普通类中的静态构造函数
class NormalClass
{
public int testInt;
public int testInt2 = 200;
public static int testInt3;
static NormalClass()
{
testInt3 = 300;
Console.WriteLine("静态构造函数");
}
public NormalClass()
{
testInt = 100;
testInt3 = 300;
Console.WriteLine("构造函数");
}
}
#endregion
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
Console.WriteLine(StaticClass.testInt);
Console.WriteLine(StaticClass.testInt2);
Console.WriteLine(StaticClass.testInt3);
Console.WriteLine(NormalClass.testInt3);
NormalClass n1 = new NormalClass();
Console.WriteLine(n1.testInt);
Console.WriteLine(n1.testInt2);
}
}
}