program.cs

来自「数据库系统文件举例」· CS 代码 · 共 59 行

CS
59
字号
using System;
using System.Collections.Generic;
using System.Text;
//添加命名空间
using System.Collections;

namespace EnumTest
{
    public enum SomeRootVegetables
    {
        HorseRadish,
        Radish,
        Turnip
    }

    [Flags]
    public enum Seasons
    {
        None = 0,
        Summer = 1,
        Autumn = 2,
        Winter = 4,
        Spring = 8,
        All = Summer | Autumn | Winter | Spring,
    }

    class Program
    {
        static void Main(string[] args)
        {
            // Hash table of when vegetables are available.
        Hashtable AvailableIn = new Hashtable();

        AvailableIn[SomeRootVegetables.HorseRadish] = Seasons.All;
        AvailableIn[SomeRootVegetables.Radish] = Seasons.Spring;
        AvailableIn[SomeRootVegetables.Turnip] = Seasons.Spring | 
            Seasons.Autumn;

        // Array of the seasons, using the enumeration.
        Seasons[] seasons = new Seasons[] { Seasons.Winter, Seasons.Spring, 
            Seasons.Summer, Seasons.Autumn };

        // Print information of what vegetables are available each season.
        for (int i = 0; i < seasons.Length; i++)
        {
            Console.WriteLine("\r\nThe following root vegetables are harvested in " + seasons[i].ToString("G") + ":");
            foreach (DictionaryEntry e in AvailableIn)
            {
                // A bitwise comparison.
                if (((Seasons)e.Value & seasons[i]) > 0)
                    Console.WriteLine("\t" + 
                        ((SomeRootVegetables)e.Key).ToString("G"));
            }
        }

        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?