Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enum values to string list with filter

Tags:

c#

linq

I need to return only the values from 1 omitting the Ant

    public enum AnimalCodeType
{
    Ant = 0,
    Koala = 1,
    Panda = 2,
} 

The below code gets me all values.. How do I change it

    return Enum.GetValues(typeof(AnimalCodeType)).Cast<AnimalCodeType>().Select(v => v.ToString()).ToList();        
like image 581
user2040600 Avatar asked Oct 12 '25 03:10

user2040600


1 Answers

return Enum
    .GetValues( typeof(AnimalCodeType) )
    .Cast<AnimalCodeType>()
    .Where( v => (int)v > 0 )
    .Select( v => v.ToString() )
    .ToList();
like image 81
Dai Avatar answered Oct 14 '25 19:10

Dai