cnxcfeng
//定义枚举
enum WorkType { 工程师,教师,学生 }

//遍历
Type work = typeof(WorkType);

// 检索指定枚举中常数名称的数组,返回一个string类型的数组
string[] temp = Enum.GetNames(work);

// 接下来通过遍历数组,取出枚举中的值
foreach (string str in temp)
{
    Console.WriteLine(
        
"{0} : {1}" ,
        str,
        (
int)Enum.Parse(work, str)
        );
}

结果输出:工程师:0 教师:1 学生:2

分类:

技术点:

相关文章:

  • 2021-09-24
  • 2021-10-18
  • 2021-12-06
  • 2021-09-24
  • 2021-09-24
  • 2021-09-24
  • 2018-03-01
  • 2021-08-14
猜你喜欢
  • 2021-05-26
  • 2021-12-23
  • 2021-11-13
  • 2021-09-24
  • 2021-09-24
  • 2021-09-24
  • 2021-09-24
相关资源
相似解决方案