日期:2014-05-20 浏览次数:21023 次
enum TU { A=0x01, B=0x04, C=0x05, D=0x15, E=0x0 } TU t=TU.D; t-=TU.A;//这是对的 t+=TU.A//错误 t=t+TU.A//错误 t=t-TU.A//错误
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace ConsoleApplication5 { class Program { static void Main(string[] args) { TU t = TU.One| TU.Two | TU.Four; Console.WriteLine(((Int32)t).ToString()); Console.WriteLine(t.ToString()); t -= TU.One;//从t中移除TU.One Console.WriteLine(((Int32)t).ToString()); Console.WriteLine(t.ToString()); } } [FlagsAttribute] enum TU { One = 1, Two = 2, Four = 4, Eight = 8, Sixteen =16 } }
[FlagsAttribute] enum FileOperations { Read = 1, Write = 2, Delete = 4, Hidden = 8, None = 16 }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { FileOperations f = FileOperations.Delete | FileOperations.Read; Console.WriteLine("原始的值\r\n" + f.ToString()); f -= FileOperations.Delete; Console.WriteLine("移除Delete后的值\r\n"+f.ToString()); f -= FileOperations.Read; Console.WriteLine("移除Read后的值\r\n" + f.ToString()); } [FlagsAttribute] enum FileOperations { Read = 1, Write = 2, Delete = 4, Hidden = 8, None = 16, } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { FileOperations f = FileOperations.Delete | FileOperations.Read; Console.WriteLine("原始的值\r\n" + f.ToString()); f -= FileOperations.Delete; Console.WriteLine("移除Delete后的值\r\n"+f.ToString()); f -= FileOperations.Read; Console.WriteLine("移除Read后的值\r\n" + f.ToString()); } [FlagsAttribute] enum FileOperations { Read = 1, Write = 2, Delete = 4, Hidden = 8, None = 0,//这里是主要变化 } } }