{"id":86,"date":"2015-06-18T22:43:10","date_gmt":"2015-06-18T14:43:10","guid":{"rendered":"https:\/\/blog.freesilo.com\/?p=86"},"modified":"2016-12-27T14:26:25","modified_gmt":"2016-12-27T06:26:25","slug":"c-%e6%9e%9a%e4%b8%be%e3%80%81%e5%ad%97%e7%ac%a6%e4%b8%b2%e3%80%81%e5%80%bc%e7%9a%84%e7%9b%b8%e4%ba%92%e8%bd%ac%e6%8d%a2","status":"publish","type":"post","link":"https:\/\/freesilo.com\/?p=86","title":{"rendered":"C# \u679a\u4e3e\u3001\u5b57\u7b26\u4e32\u3001\u503c\u7684\u76f8\u4e92\u8f6c\u6362"},"content":{"rendered":"<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">using System;\r\n\r\nclass Program\r\n{\r\n    public enum Color\r\n    {\r\n        Red = 0xff0000,\r\n        Orange = 0xFFA500,\r\n        Yellow = 0xFFFF00,\r\n        Lime = 0x00FF00,\r\n        Cyan = 0x00FFFF,\r\n        Blue = 0x0000FF,\r\n        Purple = 0x800080\r\n    }\r\n\r\n    static void Main(string&#x5B;] args)\r\n    {\r\n        Color color = Color.Blue;\r\n        string colorString = &quot; Blue &quot;;\r\n        int colorValue = 0x0000FF;\r\n\r\n        \/\/ \u679a\u4e3e\u8f6c\u5b57\u7b26\u4e32\r\n        string enumStringOne = color.ToString(); \/\/\u6548\u7387\u4f4e\uff0c\u4e0d\u63a8\u8350\r\n        string enumStringTwo = Enum.GetName(typeof(Color), color);\/\/\u63a8\u8350\r\n\r\n        \/\/ \u679a\u4e3e\u8f6c\u503c\r\n        int enumValueOne = color.GetHashCode();\r\n        int enumValueTwo = (int)color;\r\n        int enumValueThree = Convert.ToInt32(color);\r\n\r\n        \/\/ \u5b57\u7b26\u4e32\u8f6c\u679a\u4e3e\r\n        Color enumOne = (Color)Enum.Parse(typeof(Color), colorString);\r\n\r\n        \/\/ \u5b57\u7b26\u4e32\u8f6c\u503c\r\n        int enumValueFour = (int)Enum.Parse(typeof(Color), colorString);\r\n\r\n        \/\/ \u503c\u8f6c\u679a\u4e3e\r\n        Color enumTwo = (Color)colorValue;\r\n        Color enumThree = (Color)Enum.ToObject(typeof(Color), colorValue);\r\n\r\n        \/\/ \u503c\u8f6c\u5b57\u7b26\u4e32\r\n        string enumStringThree = Enum.GetName(typeof(Color), colorValue);\r\n\r\n    }\r\n}\r\n\r\n\/\/ \u5047\u8bbe\u6709\u679a\u4e3e\u503c\u5982\u4e0b\uff1a\r\npublic enum DbProviderType\r\n{\r\n    SqlServer,\r\n    Oracle\r\n}\r\n\r\n\/\/ 1\u3001\u5c06\u679a\u4e3e\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\uff1a\r\nstring  strDbType  =  DbProviderType.SqlServer.ToString();\r\n\/\/ 2\u3001\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u679a\u4e3e\uff1a\r\n\r\nDbProviderType dbType  =  (DbProviderType)Enum.Parse( typeof (DbProviderType), strDbType,  true );<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>using System; class Program { public enu&#8230;<br \/><a class=\"read-more-button\" href=\"https:\/\/freesilo.com\/?p=86\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-86","post","type-post","status-publish","format-standard","hentry","category-csharp"],"_links":{"self":[{"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/posts\/86","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/freesilo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=86"}],"version-history":[{"count":2,"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/posts\/86\/revisions"}],"predecessor-version":[{"id":431,"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/posts\/86\/revisions\/431"}],"wp:attachment":[{"href":"https:\/\/freesilo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=86"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/freesilo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=86"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/freesilo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=86"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}