110,567
社区成员
发帖
与我相关
我的任务
分享
public class ClassEnum
{
public enum SexKind
{
Male,
Female
}
}
public static void Main()
{
Type Sexs = typeof(ClassEnum.SexKind);
Console.WriteLine("The kinds of the Sex:");
foreach (string s in Enum.GetNames(Sexs))
{
Console.WriteLine(s);
}
}
private static string[] GetEnumNames(Type type)
{
if (type.IsEnum)
{
return Enum.GetNames(type);
}
throw new ArgumentException("type is not enum");
}
static void Main(string[] args)
{
foreach (var item in GetEnumNames(typeof(StringComparison)))
{
Console.WriteLine(item);
}
Console.ReadKey();
}
public static void NewMethod(Type t)
{
Console.WriteLine("The kinds of the Sex:");
foreach (string s in Enum.GetNames(t))
{
Console.WriteLine(s);
}
}
B:
public enum SexKind
{
Male,
Female
}
Main:
A.NewMethod(typeof(ConsoleApplication1.B.SexKind));
//枚举类
public class ClassB
{
public ClassB()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public enum SexKind
{
Male,
Female
}
}
//遍历类
public class GetEnumValues
{
public GetEnumValues ()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public static void Main()
{
Type Sexs = typeof(SexKind);
Console.WriteLine("The kinds of the Sex:");
ClassB mClassEnum=new ClassB ();
foreach (string s in mClassEnum.Enum.GetNames(Sexs))
{
Console.WriteLine(s);
}
}
}