C# 枚举到组合框,某些枚举元素除外

C# 枚举到组合框,某些枚举元素除外,c#,C#,例如,我有enum: private enum Categories { foo, fooBar, Bar } 通过这种方式,我使用enum的元素填充组合框: myComboBox.ItemsSource = Enum.GetValues(typeof(Categories)).Cast<Categories>(); myComboBox.ItemsSource=Enum.GetValues(typeof(Categories)).Cast(); 但是如何绑定枚举除Catego

例如,我有enum:

private enum Categories
{
foo,
fooBar,
Bar
}
通过这种方式,我使用enum的元素填充组合框:

myComboBox.ItemsSource = Enum.GetValues(typeof(Categories)).Cast<Categories>();
myComboBox.ItemsSource=Enum.GetValues(typeof(Categories)).Cast();

但是如何绑定枚举除Categories.fooBar以外的所有元素呢?

例如,您可以使用
Where

Enum.GetValues(typeof(Categories))
      .Cast<Categories>()
      .Where(x => x != Categories.fooBar).ToList();
Enum.GetValues(typeof(Categories))
.Cast()
.Where(x=>x!=Categories.fooBar).ToList();

您可以在以下位置使用

Enum.GetValues(typeof(Categories))
      .Cast<Categories>()
      .Where(x => x != Categories.fooBar).ToList();
Enum.GetValues(typeof(Categories))
.Cast()
.Where(x=>x!=Categories.fooBar).ToList();

使用():如果需要添加异常,只需将这些项目添加到列表exceptValues或内联声明中即可

var exceptValues = new[] {Categories.fooBar};
var source = Enum.GetValues(typeof(Categories)).Cast<Categories>().Except(exceptValues);
var exceptValues=new[]{Categories.fooBar};
var source=Enum.GetValues(typeof(Categories)).Cast()。除了(exceptValues);

var source=Enum.GetValues(typeof(Categories)).Cast()。除了(new[]{Categories.fooBar})

干杯。

使用():如果需要添加异常,只需将这些项目添加到列表exceptValues或内联声明中即可

var exceptValues = new[] {Categories.fooBar};
var source = Enum.GetValues(typeof(Categories)).Cast<Categories>().Except(exceptValues);
var exceptValues=new[]{Categories.fooBar};
var source=Enum.GetValues(typeof(Categories)).Cast()。除了(exceptValues);

var source=Enum.GetValues(typeof(Categories)).Cast()。除了(new[]{Categories.fooBar})

干杯。

我支持你@Giora Guttsait,一个在这种情况下不太适合的地方。我支持你@Giora Guttsait,一个在这种情况下不太适合的地方。