Пример #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("**** Fun with Enums *****");
            // Make an EmpTypeEnum variable.
            EmpTypeEnum emp = EmpTypeEnum.Contractor;

            AskForBonus(emp);
            Console.ReadLine();
            // Make a contractor type.
            EmpTypeEnum emp2 = EmpTypeEnum.Contractor;

            AskForBonus(emp2);
            // Print storage for the enum.
            Console.WriteLine("EmpTypeEnum uses a {0} for storage",
                              Enum.GetUnderlyingType(emp2.GetType()));
            Console.ReadLine();
            // This time use typeof to extract a Type.
            Console.WriteLine("EmpTypeEnum uses a {0} for storage",
                              Enum.GetUnderlyingType(typeof(EmpTypeEnum)));
            // Prints out "emp is a Contractor".
            Console.WriteLine("emp2 is a {0}.", emp2.ToString());
            Console.ReadLine();
            EmpTypeEnum e2 = EmpTypeEnum.Contractor;
            // These types are enums in the System namespace.
            DayOfWeek    day = DayOfWeek.Monday;
            ConsoleColor cc  = ConsoleColor.Gray;

            EvaluateEnum(e2);
            EvaluateEnum(day);
            EvaluateEnum(cc);
            Console.ReadLine();
        }
Пример #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("**** Fun with Enums *****\n");
            EmpTypeEnum e2 = EmpTypeEnum.Contractor;

            // These types are enums in the System namespace.
            DayOfWeek    day = DayOfWeek.Monday;
            ConsoleColor cc  = ConsoleColor.Gray;

            EvaluateEnum(e2);
            EvaluateEnum(day);
            EvaluateEnum(cc);

            Enum.Format(typeof(EmpTypeEnum), e2, "x");
            Console.ReadLine();
        }
Пример #3
0
        static void AskForBonus(EmpTypeEnum e)
        {
            switch (e)
            {
            case EmpTypeEnum.Manager:
                Console.WriteLine("How about stock options instead?");
                break;

            case EmpTypeEnum.Grunt:
                Console.WriteLine("You have got to be kidding...");
                break;

            case EmpTypeEnum.Contractor:
                Console.WriteLine("You already get enough cash...");
                break;

            case EmpTypeEnum.VicePresident:
                Console.WriteLine("VERY GOOD, Sir!");
                break;
            }
        }
Пример #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("**** Fun with Enums ****");

            // EmpTypeEnum emp = EmpTypeEnum.Contractor;
            // AskForBonus(emp);
            //
            // Console.WriteLine("EmpTypeEnum uses a {0} for storage",Enum.GetUnderlyingType(emp.GetType()));
            // Console.WriteLine(emp.GetType());
            // Console.WriteLine("EmpTypeEnum uses a {0} for storage",Enum.GetUnderlyingType(typeof(EmpTypeEnum)));
            // EmpTypeEnum emp = EmpTypeEnum.Contractor;
            // Console.WriteLine("{0} = {1}", emp.ToString(), (byte) emp);
            // Console.ReadLine();

            EmpTypeEnum e2 = EmpTypeEnum.Contractor;

            DayOfWeek    day = DayOfWeek.Monday;
            ConsoleColor cc  = ConsoleColor.Gray;

            EvaluateEnum(e2);
            EvaluateEnum(day);
            EvaluateEnum(cc);
            Console.ReadLine();
        }