您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
语法
[Flags]
public enum Permission
{
create = 1,
read = 2,
update = 4,
delete = 8,
}
注意事项
应用
使用
//初始化
WeekEnum week = (WeekEnum)127;
Console.WriteLine(week.ToString()); //输出 Sunday, Monday, Tuesday, Wendnesday, Thursday, Friday, Saturday
WeekEnum week = WeekEnum.Sunday;
//添加一个星期
week = week | WeekEnum.Monday;
Console.WriteLine(week.ToString()); // 输出Sunday, Monday
//去掉一个星期
week = week & ~WeekEnum.Sunday;
Console.WriteLine(week.ToString()); //输出 Monday
//判断是否有某个元素
obj.HasFlag() // 返回True False
string day = "monday";
WeekEnum today = (WeekEnum)Enum.Parse(typeof(WeekEnum), day, true);
// 最后一个参数标识字符串是否区分大小写
xiupublic enum Color : short
{
}
// 可以变化为 byte short int 等类型
public enum Suits
{
Spades,
Hearts,
Clubs,
Diamonds,
NumSuits
}
private static void Main(string[] args)
{
foreach (Suits suit in Enum.GetValues(typeof(Suits)))
{
Console.WriteLine((int)suit+ ":" + suit);
}
}
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。