vr引擎设计-c#基础第八天

128 阅读1分钟

枚举的应用

         enum state
    {
        开局,胜利,失败,平局
    }
    static void Main(string[]arge)
    {
        //枚举类型 Enum.getNames(typeof(State))得到枚举中所以名字
        foreach (string i in Enum.GetNames(typeof(state)))
        {
            Console.WriteLine(i);
        }
        //得到枚举中所以名字对应的编号值
        foreach(int i in Enum.GetValues(typeof(state)))
        {
            Console.WriteLine(i);
        }
       
    }

image.png

结构体

表示一堆不同类型的数据 结构体可以帮我们处理不同类型的数据

表示形式

       struct Student
    {
        public double hight;
        public int year;
        public string name;
        public int id;
        public string[] hobby;
    }
    static void Main(string[]arge)
    {
        Student student1;
        student1.hight = 1.9;
        Console.WriteLine(student1.hight);
        Student student2;
        student2.hight = 1.5;
        Console.WriteLine(student2.hight);
    }

image.png

try{}catch{}finally{}异常捕获

表现形式

        try
        {
            //try中填要检测的代码(哪一行代码出错就会立刻停下来,去catch执行代码)

        }
        catch//catch(IndexOutOTRangeException)这个就是表示下标溢出的特别表达
        {
            //代码出错就执行这里的代码
        }
        finally
        {
            //不管代码会不会出错都会执行这一行的代码
        }