C# 实验报告一 枚举 结构体
实验一C#流程控制(控制台程序)
【实验目的】
掌握C#基本语法,掌握复杂的数据类型,能熟练使用流程控制、函数定义及其调用,熟悉VS.NET 2005开发环境、CSC编译器的使用。
【实验要求】
1.是一个基于SDK开发的控制台应用程序,功能自定义。
2.要体现流程控制,如分支、循环等。
3.要有结构体、枚举等的应用。
4.要有自定义函数的应用。
5.要用CSC编译器进行代码文件的编译与调试。
【实验步骤】(要求自己填写详细的实验步骤,设计思路和关键代码)
【实验体会及存在问题】(要求自己填写,感想、设计时碰到的问题,包括设计思想、调试等)

1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5
6 namespace ConsoleApplication3
7 {
8 publicenum Alignment
9 {
10 Left,
11 Center,
12 Right
13 }
14 struct route
15 {
16 public Alignment am;
17 publicint a;
18 }
19 class Class1
20 {
21 private route myroute;
22 publicvoid test(Alignment a)
23 {
24 switch (a)
25 {
26 case Alignment.Left:
27 Console.WriteLine("向左走一百米");
28 break;
29 case Alignment.Right:
30 Console.WriteLine("向右走一百米");
31 break;
32 case Alignment.Center:
33 Console.WriteLine("直走一百米");
34 break;
35 default:
36 throw (new System.ArgumentException("Invalid Writing Style"));
37 }
38 }
39 publicvoid test()
40 {
41 Console.WriteLine("你要走的方向:0)Left 1)Center 2)Right");
42 myroute.a= Convert.ToInt32( Console.ReadLine());
43 while (myroute. a<0|| myroute. a>2) {
44 Console.WriteLine("请输入:0或1或2");
45 myroute.a = Convert.ToInt32(Console.ReadLine());
46 }
47 Alignment a = (Alignment)Enum.Parse(typeof(Alignment), myroute.a.ToString());
48 //myroute.am = (Alignment)myroute.a;
49 test(a);
50 //Console.WriteLine(myroute.am);
51 }
52
53 publicstaticvoid Main()
54 {
55 Class1 c =new Class1();
56 c.test();
57 }
58 }
59 }
60
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5
6 namespace ConsoleApplication3
7 {
8 publicenum Alignment
9 {
10 Left,
11 Center,
12 Right
13 }
14 struct route
15 {
16 public Alignment am;
17 publicint a;
18 }
19 class Class1
20 {
21 private route myroute;
22 publicvoid test(Alignment a)
23 {
24 switch (a)
25 {
26 case Alignment.Left:
27 Console.WriteLine("向左走一百米");
28 break;
29 case Alignment.Right:
30 Console.WriteLine("向右走一百米");
31 break;
32 case Alignment.Center:
33 Console.WriteLine("直走一百米");
34 break;
35 default:
36 throw (new System.ArgumentException("Invalid Writing Style"));
37 }
38 }
39 publicvoid test()
40 {
41 Console.WriteLine("你要走的方向:0)Left 1)Center 2)Right");
42 myroute.a= Convert.ToInt32( Console.ReadLine());
43 while (myroute. a<0|| myroute. a>2) {
44 Console.WriteLine("请输入:0或1或2");
45 myroute.a = Convert.ToInt32(Console.ReadLine());
46 }
47 Alignment a = (Alignment)Enum.Parse(typeof(Alignment), myroute.a.ToString());
48 //myroute.am = (Alignment)myroute.a;
49 test(a);
50 //Console.WriteLine(myroute.am);
51 }
52
53 publicstaticvoid Main()
54 {
55 Class1 c =new Class1();
56 c.test();
57 }
58 }
59 }
60
哎呀。。。实验报告一帮别人做了几份,感觉好不爽。。。要不好拒绝。。。嗯。。。。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南