枚举值提取

Rob*_*ech 4 c# enums

我有一个枚举类型(即View).我想提取此枚举的一部分[顶部,底部,左侧,右侧,前部,后部]以添加到组合框中ComboBox.DataSource = Enum.GetValues(typeof(View_extracted)).

可能吗?

enum View {Top,Bottom,Left,Right,Front,Rear,Trimetric,Isometric,Diametric}
Run Code Online (Sandbox Code Playgroud)

View_extracted 应仅包含前6个值:

{Top,Bottom,Left,Right,Front,Rear}
Run Code Online (Sandbox Code Playgroud)

It'*_*ie. 6

LINQ救援!

Enum.GetValues(typeof(View)).Cast<View>().Take(6);
Run Code Online (Sandbox Code Playgroud)

如果你希望它是一个正确的枚举,你可以用伊尔根周围乱,但它的方式,方式更多的麻烦比它的价值.

  • +1 - 我投了票,因为它在28秒内得到了答复 (4认同)
  • 伙计们,它有效,非常感谢你给@InsNotALie的答案. (3认同)