CSharp-Learning/lessons/Lesson05/Program.cs
Rosmontis_Cloud f604d53191 Initial commit: C# 学习笔记和示例代码
- Lesson 01-10: C# 基础语法
- WebView2: 集成示例
- notes/: 详细笔记
2026-07-01 16:31:35 +08:00

43 lines
1.1 KiB
C#

using System;
using Lesson05.Models;
using Lesson05.Services;
using Lesson05.Helpers;
namespace Lesson05
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("=== 多文件项目演示 ===\n");
// 使用 Models 里的类
Person p = new Person("无言势", 25);
p.SayHi();
// 使用 Property
p.Age = -5; // 会自动限制范围
Console.WriteLine($"设置后年龄: {p.Age}");
p.Age = 200;
Console.WriteLine($"设置后年龄: {p.Age}");
// 使用 Services
AudioService service = new AudioService();
service.StartListening();
service.StopListening();
// 使用 Helpers
int sum = MathHelper.Add(100, 200);
Console.WriteLine($"\n100 + 200 = {sum}");
// 演示 private 无法访问
// p.secret = "xxx"; // 编译错误
// p.SetSecret("xxx"); // 编译错误
Console.WriteLine("\n=== 演示完成 ===");
Console.ReadLine();
}
}
}