您好,登錄后才能下訂單哦!
語法
[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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。