How to perform LINQ query over Enum?

前端 未结 6 2009
甜味超标
甜味超标 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 20:04

    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.

提交回复
热议问题