How to perform LINQ query over Enum?

前端 未结 6 2010
甜味超标
甜味超标 2021-02-03 19:44

Below is my Enumerator List:

public enum StatusEnum
{
    Open = 1,
    Rejected = 2,
    Accepted = 3,
    Started = 4,
    Completed = 5,
    Canc         


        
6条回答
  •  醉话见心
    2021-02-03 19:59

    return Enum.GetValues(typeof(Activity.StatusEnum)).Cast().Where((n, x) => x < 4);
    

    If you want to be able to change the list of items, just add them into a List and use Contains:

    var listValid = new List() { Activity.StatusEnum.Open, Activity.StatusEnum.Rejected, Activity.StatusEnum.Accepted, Activity.StatusEnum.Started };
    return Enum.GetValues(typeof(Activity.StatusEnum)).Cast().Where(n => listValid.Contains(n));
    

提交回复
热议问题