CSharp-Learning/lessons/Lesson05/Program.cs

43 lines
1.1 KiB
C#
Raw Permalink Normal View History

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();
}
}
}