对于enum类型:

使用foreach遍历enum类型的元素并填充combox

      

 foreach ( HatchStyle hs1 in Enum.GetValues(typeof(HatchStyle)))
            {
                comboBox1.Items.Add(hs1.ToString());
            }

 获取enum项个数(使用反射)

  private static int NumberOfEnumValues()
    {
          return typeof(TStageEnum).GetFields(BindingFlags.Public | BindingFlags.Static).Length;
    }

 

字符串如何转换在枚举类型

//一个enum的例子
enum Colors { Red = 1, Green = 2, Blue = 4, Yellow = 8 };
//转换的例子
Colors myColor = (Colors)Enum.Parse(typeof(Colors), "Yellow");

 

相关文章:

  • 2022-12-23
  • 2021-07-17
  • 2022-02-03
  • 2022-01-10
  • 2021-04-06
  • 2021-09-29
猜你喜欢
  • 2021-09-09
  • 2021-09-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案