C#枚舉類型使用的一點總結
作者:佚名
C#枚舉類型使用的一點總結主要是向你講解C#枚舉類型使用過程中的一點體會和知識點的強調,希望對你學習C#枚舉類型有所幫助。
C#枚舉類型使用的時候需要掌握的有哪些方面呢?首先我們來看看一個例子:
- public enum Colors { Red = 1, Green = 2,
- Blue = 4, Yellow = 8 };
- The entries of the Colors Enum are:
- Red
- Green
- Blue
- Yellow
C#枚舉類型使用的一點總結之根據(jù)name獲得Enum的類型:
- Colors mycolor = (Colors)Enum.Parse(
- typeof(Colors),"red",true);
- (int)mycolor1=1
- mycolor1.GetTypeCode=Int32
C#枚舉類型使用的一點總結之根據(jù)value獲得Enum的類型:
- Colors mycolor = (Colors)Enum.Parse(
- typeof(Colors),"1",true);
- mycolor2.ToString()=Red
- mycolor2.GetTypeCode=Int32
C#枚舉類型使用的一點總結之遍歷枚舉內容
- foreach(string s in Enum.GetNames(typeof(Colors)))
- {
- //to do
- }
- Colors myOrange = (Colors)Enum.Parse(
- typeof(Colors), "Red, Blue,Yellow");
- The myOrange value has the combined
- entries of [myOrange.ToString()]=13
- Colors myOrange2 = (Colors)Enum.Parse(
- typeof(Colors), "Red, Blue");
- The myOrange2 value has the combined
- entries of [myOrange2.ToString()]=5
C#枚舉類型使用的一點總結的內容就向你介紹到這里,希望對你了解和學習C#枚舉類型有所幫助。
【編輯推薦】
責任編輯:仲衡
來源:
tz8.net