zoukankan      html  css  js  c++  java
  • How do I convert an enum to a list in C#?

    How do I convert an enum to a list in C#?

    This will return an IEnumerable<SomeEnum> of all the values of an Enum.

    Enum.GetValues(typeof(SomeEnum)).Cast<SomeEnum>();
    

    If you want that to be a List<SomeEnum>, just add .ToList() after .Cast<SomeEnum>().

    To use the Cast function on an Array you need to have the System.Linq in your using section.

  • 相关阅读:
    37.js----浅谈js原型的理解
    iOS
    iOS
    iOS
    python3
    ios
    iOS
    python3
    python3
    iOS
  • 原文地址:https://www.cnblogs.com/dupeng0811/p/how-do-i-convert-an-enum-to-a-list-in-c.html
Copyright © 2011-2022 走看看