涓銆佹灇涓剧殑姒傚康锛

C# 鏋氫妇锛圗num锛, 鏋氫妇绫诲瀷鏄敤浜庡0鏄庝竴缁勫懡鍚嶇殑甯告暟鐨勫熀鏈暟鎹被鍨嬶紙鍊肩被鍨嬶級锛

浜屻佹灇涓剧殑瀹氫箟锛

澹版槑 enum 鍙橀噺锛氥

enum <enum_name> {enumeration list};

鍏朵腑 enum_name 鎸囧畾鏋氫妇鐨勭被鍨嬪悕绉帮紝enumeration list 鏄竴涓敤閫楀彿鍒嗛殧鐨勬爣璇嗙鍒楄〃锛

鏋氫妇鍒楄〃涓殑姣忎釜绗﹀彿浠h〃涓涓暣鏁板硷紝涓涓瘮浠栧墠闈㈢殑绗﹀彿澶х殑鏁存暟鍊笺傞粯璁ゆ儏鍐典笅锛岀涓涓灇涓剧鍙风殑鍊兼槸 0銆備緥濡傦細

enum Days {Sun , Mon, tue, Fir, sat };

涓夈佹灇涓剧殑妗堜緥锛屾灇涓惧彉閲忕殑鐢ㄦ硶锛

瀹炰緥

using System;
namespace EnumApplication
{
    class EnumProgram
    {
          enum Days { Sun, Mon, tue, Wed, thu, Fri, sat };
         
          static void Main(string[] args)
          {
                int WeekdayStart = (int)Days.Mon;
                int WeekdayEnd = (int)Days.Fir;
                Console.WriteLine("Monday锛歿0}",WeekdayStart);  
                Console.WriteLine("Firday锛歿0}",WeekdayEnd );  
                Console.ReadKey();
          }    
    }
}

鍥涖丒num 绫伙細

鎵鏈夋灇涓剧被鍨嬮兘闅愬紡鍦扮户鎵 System.Enum 绫诲瀷锛 System.Enum 绫诲瀷鏄户鎵胯嚜 System.ValueType 绫诲瀷鍞竴涓嶄负鍊肩被鍨嬬殑寮曠敤绫诲瀷锛

浜斻丒num 绫伙細

鏂规硶鎻忚堪
CompareTo灏嗘瀹炰緥涓庢寚瀹氬璞¤繘琛屾瘮杈冨苟杩斿洖涓涓浜岃呯殑鐩稿鍊肩殑鎸囩ず
Equals锛氭寚绀烘瀹炰緥鏄惁绛変簬鎸囧畾鐨勫璞★紱
Format鏍规嵁鎸囧畾鏍煎紡灏嗘寚瀹氭灇涓剧被鍨嬬殑鎸囧畾鍊艰浆鎹负鍏剁瓑鏁堢殑瀛楃涓茶〃绀哄舰寮
GetName鍦ㄦ寚瀹氭灇涓句腑妫绱㈠叿鏈夋寚瀹氬肩殑甯告暟鐨勫悕绉
GetNames妫绱㈡寚瀹氭灇涓句腑甯告暟鍚嶇О鐨勬暟缁
GetTypeCode杩斿洖姝ゅ疄渚嬬殑鍩虹TypeCode
GetUnderlyingTye杩斿洖鎸囧畾鏋氫妇鐨勫熀纭绫诲瀷
GetValues鎸囧畾鏋氫妇涓父鏁板肩殑鏁扮粍
HasFlag纭畾褰撳墠瀹炰緥涓槸鍚﹁缃簡涓涓垨澶氫釜浣嶅煙
IsDefined杩斿洖鎸囧畾鏋氫妇涓槸鍚﹀瓨鍦ㄥ叿鏈夋寚瀹氬肩殑甯告暟鐨勬寚绀
Parse灏嗕竴涓垨澶氫釜鏋氫妇甯告暟鐨勫悕绉版垨鏁板瓧鍊煎緱瀛楃涓茶〃绀鸿浆鎹㈡垚绛夋晥寰楁灇涓惧璞★紝涓涓弬鏁版寚瀹氳鎿嶄綔鏄惁涓嶅尯鍒嗗ぇ灏忓啓
TryParse灏嗕竴涓垨澶氫釜鏋氫妇甯告暟寰楀悕绉版垨鏁板瓧鍊煎緱瀛楃涓茶〃绀鸿浆鎹㈡垚绛夋晥寰楁灇涓惧璞★紝鐢ㄤ簬鎸囩ず杞崲鏄惁鎴愬姛寰楄繑鍥炲

鍏佹爣蹇楁灇涓/浣嶆灇涓

快三大小倍投技巧—官方网址22270.COMC# 鏍囪鏋氫妇锛團lags)锛氭灇涓剧被鍨嬫槸鐢ㄤ簬澹版槑涓缁勫懡鍚嶅緱甯告暟寰楀熀鏈被鍨嬫暟鎹紙鍊肩被鍨嬶級銆

鏋氫妇鍊兼槸浜掓枼寰椼快三大小倍投技巧—官方网址22270.COM鑰屼綅鏍囪闆嗗悎鏄竴绉嶇敱缁勫悎鍑虹幇寰楀厓绱犲舰鎴愬緱鍒楄〃锛岄氬父璁捐涓轰互"浣嶆垨"杩愮畻缁勫悎鏂板笺

銆銆

鏋氫妇绫诲瀷鍒欓氬父琛ㄨ揪涓绉嶈涔夌浉瀵圭嫭绔嬪緱鏁板奸泦鍚堛快三大小倍投技巧—官方网址22270.COM鑰屼互鏋氫妇绫诲瀷鏉ュ疄鐜颁綅鏍囪闆嗗悎鏄渶瀹岀編寰楃粍鍚堬紝绠绉颁綅鏋氫妇銆

涓冦佷綅鏋氫妇寰楀畾涔夈銆

///<summary>
銆銆/// 鏉冮檺鏋氫妇
銆銆///</summary>
銆銆[Flags]
銆銆public enum permission銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆 娉ㄦ剰鍔犱簡[Flags]鐗规у悗鏈変笁绉嶅啓娉曪紝
銆銆{銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆 涓绉嶆槸浣跨敤<<绗﹀彿锛
  銆銆  Unknown = 0; // 涔熷彲浠ュ啓鎴0x00鎴0銆銆銆銆銆銆銆銆銆銆銆銆銆绗簩绉嶆槸0x01,銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆
銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆杩樻湁涓绉嶆槸鐩存帴鍐0锛1锛2锛4锛8....锛
   銆銆 Create = 1<<0, // 0x01鎴1銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆涓鑸潵璇存槸2鐨刵娆℃柟鏉ヨ〃绀恒傘銆
銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆  娉細<<宸︽搷浣滅锛岃〃绀哄杩欎釜鏁拌繘琛岀Щ浣嶃
    銆銆Read = 1<<1,  //0x02鎴2

   銆銆 Update = 1<<2, //0x04鎴4

   銆銆 Delete = 1<<3  //0x08鎴8
銆銆}

鍏佷綅鏋氫妇鐨勫疄渚

//1銆佺粰鐢ㄦ埛鍒涘缓銆佽鍙栵紝淇敼鍜屽垹闄ょ殑鏉冮檺
var parmission = Permission.Create | parmission.Read | parmission.Update | parmission.Delete;

//2銆佸幓鎺夌敤鎴风殑淇敼鍜屽垹闄ゆ潈闄
parmission = parmission &~parmission.Update;
parmission = parmission &~parmission.Delete;

//3銆佺粰鐢ㄦ埛鍔犱笂淇敼鐨勬潈闄
parmission = parmission | parmission.Update;

//4銆佸垽鏂敤鎴锋槸鍚︽湁鍒涘缓鐨勬潈闄
var isCreate = (parmission & parmission.Create)!=0;
//鎴栬
var isCreate = (parmission & parmission.Create)==parmission.Create;
銆銆杩欐椂parmission鏋氫妇鐨勫煎皢鍙樻垚0+1+4=5锛屽畠鐨凾oSting()灏嗗彉鎴“parmission.Create锛
銆銆parmission.Read”,parmission.Update; 杩欓噷鎴戜滑鍙互瑙i噴涓轰粈涔堢浜斾釜鍊糄elete鏄8鑰屼笉鑳芥垚涓5銆快三大小倍投技巧—官方网址22270.COM
銆銆涔熷氨鏄瀹冪殑鍊间笉搴旇鏄墠鍑犻」鍊肩殑澶嶅悎鍊笺備竴涓瘮杈冪畝鍗曠殑鏂规硶
銆銆灏辨槸鐢2鐨刵娆℃柟鏉ヤ緷娆′綅姣忎竴椤硅祴鍊硷紝渚嬪锛1锛2锛4锛8锛16锛32锛64.......銆

鍘熸枃鍦板潃锛歨ttp://www.cnblogs.com/chenyao-1424433719/p/11213658.html