C#密封类sealed


C#使用关键字sealed将类定义为密封类,该类不能被继承或修改

using System;
namespace HxRuntech
{
    sealed class T1
    {
        public enum Week
        {
            Sunday = 0,
            Monday = 1,
            Tuesday = 2,
            Wednesday = 3,
            Thursday = 4,
            Friday = 5,
            Saturday = 6,
        }

        static void Main()
        {
            CheckWeek(Week.Tuesday);
        }

        static void CheckWeek(Week day)
        {
            switch (day)
            {
                case Week.Sunday:
                    Console.WriteLine("hello sunday");
                    break;
                case Week.Monday:
                    Console.WriteLine("hello Monday");
                    break;
                case Week.Tuesday:
                    Console.WriteLine("hello Tuesday");
                    break;
                case Week.Wednesday:
                    Console.WriteLine("hello Wednesday");
                    break;
                case Week.Thursday:
                    Console.WriteLine("hello Thursday");
                    break;
                case Week.Friday:
                    Console.WriteLine("hello Friday");
                    break;
                case Week.Saturday:
                    Console.WriteLine("hello Saturday");
                    break;
                default:
                    Console.WriteLine("Hello World");
                    break;
            }
        }
    }
}