枚举—C#基础回顾
為什么80%的碼農都做不了架構師?>>> ??
?
2.6.cs
/* author:frank datetime:2017-7-19 11:48:23 */ using System; using systemIO = System.IO;//給引用的名稱空間一個別名 using Introduction = Sample.Wrox.ProCSharp.Basics;namespace Sample {public class Program{public enum TimeOfDay{Morning = 0,Afternoon = 1,Evening = 2}public static int Main(string[] agrs){systemIO::FileInfo file = new systemIO::FileInfo(@"G:\Documents\CSharp\Sample\2\2.6.cs");//使用別名名稱空間Introduction::NamespaceExample NSEx = new Introduction::NamespaceExample();//使用別名限定,然后使用其中的類。Console.WriteLine(NSEx.GetNamespace());WriteGreeting(TimeOfDay.Morning);Console.WriteLine(TimeOfDay.Morning.ToString());//返回枚舉字符串TimeOfDay time2 = (TimeOfDay)Enum.Parse(typeof(TimeOfDay),"afternoon",true);//將字符串轉換為枚舉類型Console.WriteLine((int)time2);//將枚舉類型顯示轉換為整型,將會輸出枚舉對應的整型。return 0;}public static void WriteGreeting(TimeOfDay timeOfDay){switch(timeOfDay){case TimeOfDay.Morning:Console.WriteLine("Good morning!");break;case TimeOfDay.Afternoon:Console.WriteLine("Good afternoon!");break;case TimeOfDay.Evening:Console.WriteLine("Good evening!");break;default:Console.WriteLine("Hello!");break;}}}namespace Wrox.ProCSharp.Basics{public class NamespaceExample{public string GetNamespace(){return this.GetType().Namespace;}}} }?
轉載于:https://my.oschina.net/Sadhu/blog/1477310
總結
- 上一篇: Java调用WebService接口实现
- 下一篇: Android记录24-WebView实