Reputation: 119
I have a set of enums
public enum SyncRequestTypeEnum
{
ProjectLevel=1,
DiffSync=2,
FullSync=3
}
I want to display these enums in a drop down list except ProjectLevel. Can I get these details using linq? Can someone help on this?
Upvotes: 5
Views: 5728
Reputation: 251
Found myself in a similar situation where I needed the names of the Enum instead of their values.
To do that you could use this:
var exceptThese = new List<string> { nameof(SyncRequestTypeEnum.ProjectLevel) };
var result = Enum.GetNames<SyncRequestTypeEnum>().ToList().Except(exceptThese);
Upvotes: 0
Reputation: 31239
Maybe something like this:
var result = Enum
.GetValues(typeof(SyncRequestTypeEnum))
.Cast<SyncRequestTypeEnum>()
.Where(w =>w!=SyncRequestTypeEnum.ProjectLevel)
.ToList();
Upvotes: 12