How to perform LINQ query over Enum?

前端 未结 6 588
梦如初夏
梦如初夏 2021-02-03 19:42

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

    Well if you're going to hard code the items that should be in the list anyway, why not just do this:

    public static List StatusList()
    {
        return new List
        { 
            Activity.StatusEnum.Open, 
            Activity.StatusEnum.Rejected, 
            Activity.StatusEnum.Accepted, 
            Activity.StatusEnum.Started 
        };
    }
    

    You could also dispose of the List and just return the array itself. As long as you know these are the items you want, then there's no need for Linq.

提交回复
热议问题