![]() ![]() ![]() | introductory-examples/enumeration-types/ex.cs - Demonstration of enumeration types in C#. | Lecture 2 - slide 8 : 43 Program 1 |
using System; class NonSimpleTypeDemo{ public enum Ranking {Bad, OK, Good} public enum OnOff: byte{ On = 1, Off = 0} public static void Main(){ OnOff status = OnOff.On; Console.WriteLine(); Console.WriteLine("Status is {0}", status); Ranking r = Ranking.OK; Console.WriteLine("Ranking is {0}", r ); Console.WriteLine("Ranking is {0}", r+1); Console.WriteLine("Ranking is {0}", r+2); bool res1 = Enum.IsDefined(typeof(Ranking), 3); Console.WriteLine("{0} defined: {1}", 3, res1); bool res2= Enum.IsDefined(typeof(Ranking), Ranking.Good); Console.WriteLine("{0} defined: {1}", Ranking.Good , res2); bool res3= Enum.IsDefined(typeof(Ranking), 2); Console.WriteLine("{0} defined: {1}", 2 , res3); foreach(string s in Enum.GetNames(typeof(Ranking))) Console.WriteLine(s); } }