Reputation: 611
Let's say I have an enum that contains the properties:
public enum MyEnum
{
Yes,
No,
None
}
I can bind these values to a ComboBox pretty easily. However, let's say I want to omit the "None" value - what's the best way to go about this?
Upvotes: 1
Views: 1865
Reputation: 14618
You can use Enum.GetValues() and then Cast
to get an IEnumerable
, then filter the results based on the ones you want to omit, e.g:
var items = Enum.GetValues(typeof(MyEnum)).Cast<MyEnum>()
.Where(e => e != MyEnum.None);
Upvotes: 4