有很多将枚举类型的都没有说详细...所以我这里贴出来一下,免得我忘记..................................
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 枚举类型怎么写 { class Program { public enum ServicePut : byte { 安装服务 = 2, 启动服务 = 4, 卸载服务 = 8, 验证服务状态 = 16, 停止服务 = 32, 嘻嘻 = 64, 哈哈 = 128, } public static void DeployService(ServicePut jsp) { if ((jsp & ServicePut.安装服务) == ServicePut.安装服务) { Console.WriteLine("安装服务"); } if ((jsp & ServicePut.启动服务) == ServicePut.启动服务) { Console.WriteLine("启动服务"); } if ((jsp & ServicePut.卸载服务) == ServicePut.卸载服务) { Console.WriteLine("卸载服务"); } if ((jsp & ServicePut.验证服务状态) == ServicePut.验证服务状态) { Console.WriteLine("验证服务状态"); } if ((jsp & ServicePut.停止服务) == ServicePut.停止服务) { Console.WriteLine("停止服务"); } if ((jsp & ServicePut.嘻嘻) == ServicePut.嘻嘻) { Console.WriteLine("嘻嘻"); } if ((jsp & ServicePut.哈哈) == ServicePut.哈哈) { Console.WriteLine("哈哈"); } } static void Main(string[] args) { DeployService(ServicePut.安装服务); DeployService(ServicePut.启动服务); DeployService(ServicePut.卸载服务); DeployService(ServicePut.验证服务状态); DeployService(ServicePut.停止服务); DeployService(ServicePut.嘻嘻); Console.WriteLine("--------------------------"); DeployService(ServicePut.安装服务 | ServicePut.启动服务); DeployService(ServicePut.安装服务 | ServicePut.停止服务); DeployService(ServicePut.验证服务状态 | ServicePut.停止服务); DeployService(ServicePut.启动服务 | ServicePut.停止服务); DeployService(ServicePut.哈哈 | ServicePut.启动服务); DeployService(ServicePut.嘻嘻 | ServicePut.停止服务); Console.ReadKey(); } } }