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,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
@@ -0,0 +1,118 @@
namespace Lesson2_成员变量和访问修饰符
{
#region
// 类和对象
// 声明类
//class 类名
//{
// //形容一类对象的:
// //特征-成员变量//////////////////////////////////本课重点
// //保护特征-成员属性
// //构造函数和析构函数
// //索引器
// //运算符重载
// //静态成员
//}
// 实例化对象
// 类名 变量名;
// 类名 变量名 = null;
// 类名 变量名 = new 类名();
#endregion
#region
//基本规则
//1.声明在类语句块中
//2.用来描述对象的特征
//3.可以是任意变量类型
//4.数量不做限制
//5.是否赋值根据需求决定
//性别
enum E_Sex
{
male = 0,
female = 1
}
//位置
struct Position
{
public int x;
public int y;
public Position(int x, int y)
{
this.x = x;
this.y = y;
}
}
//宠物
class Pet
{
}
//人
class Human
{
//特征-成员变量
//姓名
public string name = "HK";//可以初始化(但意义不大),结构体中不可以
//年龄
public int age;
//性别
public E_Sex sex;
//伴侣
public Human girlfriend;
//类中这么写是可以的 因为类会默认为null
//结构体不能这么写 因为结构体必须初始化
//注意!
//在类中声明一个类名相同的成员变量时
//不能对其进行实例化(可以为null,但是不能直接初始化new一个,会造成死循环)
public Human[] friend;
public Position pos;
public Pet pet;
}
#endregion
#region 访
// public 公共的 自己(内部)和别人(外部)都能访问和使用
// private 私有的 自己(内部)才可以访问和使用 不写 默认为此private
// protected 保护的 自己(内部)和子类才能访问和使用
// 目前决定类内部的成员 的 访问权限
#endregion
#region
#endregion
#region
#endregion
#region
#endregion
#region
#endregion
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
#region
#endregion
Human h = new Human();
//值类型来说 数字类型的默认值都是0 bool类型都是false
//引用类型的 null
//看默认值的方法
Console.WriteLine(default(int));
Console.WriteLine(default(Human));//打印null看不到
h.age = 10;
Console.WriteLine(h.age);
}
}
}