# 枚举
有一个很有意思的地方,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
{
}
本文原文地址:https://www.5yang.cc/5047
本篇文章来源于
https://www.5yang.cc/5047 版权均归站长本人所有,如有侵权,请联系seowhy2018删除。
0 人参与评论
该文章尚未收到评论 :(
提交评论禁止带推广链接、违法词及灌水,违规将封禁账号!!了解合理带链接的方法