我想弄清楚如何在类中嵌套枚举。下面的代码是如何工作的?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Console2
{
class Program
{
class a
{
enum Days { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday };
enum Months : byte { Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec };
}
static void Main(string[] args)
{
Type weekdays = typeof(a.Days);
string s = Enum.GetName(typeof(a.Days), 4);
Console.WriteLine(s);
Console.WriteLine("The values of the Days Enum are:");
foreach (int i in Enum.GetValues(typeof(Days)))
Console.WriteLine(i);
Console.WriteLine("The names of the Days Enum are:");
foreach (string str in Enum.GetNames(typeof(Days)))
Console.WriteLine(str);
}
}
}
我可以通过简单地将枚举声明为公共来使其工作,因为它们在默认情况下是私有的。
class a { public enum Days { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday }; public enum Months : byte { Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec }; }