boutique replica bags up ideas

the best replique rolex and prices here.

julia highlight 99j hair color 10a quality straight human hair lace front wigs 8 - 24 inches pre plucked hairline 13x4 inches lace front brazilian wig onlinefor sale

Convert an Enum to a List in C#

Updated on     Kisan Patel

This tutorial will show you how to convert an enum to a generic list in C#?

For example, we have enum as shown in below code:

public enum Fruit
{
    Apple = 1,
    Banana = 2,
    Grapes = 3
}

Now, we have convert above enum to IEnumerable<Fruit> using below line of code:

Enum.GetValues(typeof(Fruit)).Cast<Fruit>();

So, If you want to convert enum into List<SelectListItem> then use below line of code:

List<SelectListItem> = Enum.GetValues(typeof(Fruit)).Cast<Fruit>()
                           .Select(x => new  SelectListItem
                               {
                                  Value = Convert.ToString((int)x),
                                  Text = x.ToString()
                               }).ToList();

C#

Leave a Reply