zoukankan      html  css  js  c++  java
  • C# Enum GetValues 将枚举转为Array

     Enum 可以通过 GetValues 将枚举转为Array .

    View Code
     1 using System;
    2
    3 enum EnumNames
    4 {
    5 liuxiaolin,
    6 zhoutianchi,
    7 zhouqihan
    8 }
    9 class EnumTest
    10 {
    11 static void Main()
    12 {
    13 int n = Enum.GetValues(typeof(EnumNames)).Length; //用Enum.GetValues(typeof(EnumNames)) 返回一个数组,length得到其长度
    14
    15 for (int i = 0;i < n;i++ )
    16 {
    17 Console.WriteLine((EnumNames)i); //(EnumNames)i 是将Int值转为枚举名.
    18 }
    19 }
    20 }
  • 相关阅读:
    禅道学习(一)
    遍历
    php特性
    jsonRPC
    model
    水仙花数(详细2
    水仙花数(详细1
    递归求n 项和
    poj 1651
    nyist 289
  • 原文地址:https://www.cnblogs.com/easyfrog/p/2318408.html
Copyright © 2011-2022 走看看