MCPcopy Create free account
hub / github.com/davidkingzyb/SCAST / Program

Class Program

test/test.cs:68–135  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

66}
67
68class Program
69{
70 private Cat cat=new Cat();
71 private List<Cat> cats;
72
73 static void Main(string[] args)
74 {
75 Console.WriteLine("--- C# 语法测试开始 ---");
76 var dog=new Dog("小黑", 3);
77
78 dog.Speak("ok");
79 Update("ok");
80 Update();
81
82
83 // 6. new 关键字 (创建对象和集合)
84 List<Animal> animals = new List<Animal>();
85
86 // 添加子类对象到父类列表 (多态)
87 animals.Add(dog);
88 animals.Add(new Cat("小白", 1));
89 animals.Add(new Dog("大黄", 5));
90
91 // 7. for 循环
92 Console.WriteLine("\n--- For 循环测试 ---");
93 for (int i = 0; i < 3; i++)
94 {
95 Console.WriteLine($"for 循环计数:{i + 1}");
96 while(true){
97 dog.Speak("white");
98 }
99
100 do{
101 Update();
102
103 }while(i>0);
104 }
105
106 // 8. foreach 循环
107 Console.WriteLine("\n--- Foreach 循环测试 ---");
108 foreach (var animal in animals)
109 {
110 animal.PrintInfo();
111
112 // 9. if 条件判断
113 if (animal.Age > 2)
114 {
115 Console.WriteLine(" -> 这是一只成年动物");
116 var a=new Dog()
117 if(a.Age>1){
118 a.Speak();
119 }
120 }
121 else
122 {
123 Console.WriteLine(" -> 这是一只幼年动物");
124 }
125

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected