5

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?

user3356020
  • 119
  • 3
  • 9
  • Take a look at this: http://stackoverflow.com/questions/61953/how-do-you-bind-an-enum-to-a-dropdownlist-control-in-asp-net. Perhaps LINQ isn't necessary. – shree.pat18 Jun 16 '14 at 06:19

2 Answers2

12

Maybe something like this:

var result = Enum
        .GetValues(typeof(SyncRequestTypeEnum))
        .Cast<SyncRequestTypeEnum>()
        .Where(w =>w!=SyncRequestTypeEnum.ProjectLevel)
        .ToList();
Arion
  • 31,011
  • 10
  • 70
  • 88
0

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);
George Feakes
  • 152
  • 2
  • 13