コード例 #1
0
        public void enumTester()
        {
            ShippingMethod method = ShippingMethod.Express;

            Console.WriteLine((int)method);

            var methodId = 3;

            Console.WriteLine("\n" + (ShippingMethod)methodId);

            Console.WriteLine("\n" + method.ToString());

            string         methodName     = "Express";
            ShippingMethod shippingMethod = (ShippingMethod)Enum.Parse(typeof(ShippingMethod), methodName);

            Console.WriteLine("\n" + shippingMethod);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: jwuestef/C-Beginner-Basics
        static void Main(string[] args)
        {
            // Given the name, print out the number
            ShippingMethod method = ShippingMethod.Express;

            Console.WriteLine((int)method);

            // Given the number, print out the name
            int methodID = 3;

            Console.WriteLine((ShippingMethod)methodID);

            // Print out the name
            Console.WriteLine(method.ToString());

            // Convert from string to enum
            string         methodName     = "Express";
            ShippingMethod shippingMethod = (ShippingMethod)Enum.Parse(typeof(ShippingMethod), methodName);
        }