# 枚举

有一个很有意思的地方,c#的枚举有点像python的字典。然而使用起来却有些微妙的区别

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
namespace ConsoleApp1
{
    enum ori: byte
    {
        north = 1,
        south = 2,
        east = 3,
        west = 4

    }
    class Program
    {
        static void Main(string[] args)
        {
            ori mydir = ori.north;
            WriteLine($"mydir = {mydir}");
            WriteLine($"mydir = {(byte)mydir}");
            ReadKey();
        }

        }
    }

这里输出如下内容:

mydir = north
mydir = 1

如果直接调用枚举类型.属性(ori.north),他会直接输出类似python里字典的"键",也就是mydir = north
可是如果你强制显示转换为你自己的添加类型(byte),他又会如python的字典似地,输出为"值",也就是mydir = 1

# struct 结构

定义结构
使用struct关键字定义结构
struct route
{
}

最后修改:2022 年 12 月 05 日
如果觉得我的文章对你有用,请随意赞赏