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

Get enum value by string or int in C#

Updated on     Kisan Patel

This tutorial will show you how to get the enum value by string or int in C#?

For example,

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

Now, to get enum value from a string then you need to follow below approach:

Fruit foo = (Fruit) Enum.Parse(typeof(Fruit), "Apple");
Console.WriteLine(foo.ToString()); //print "Apple"
Console.WriteLine((int)foo); //print 2

If you want to get enum value from a int then you need to follow below approach:

Fruit foo = (Fruit)3;
Console.WriteLine(foo.ToString()); //print "Grapes"

OR

Fruit foo = (Fruit) Enum.ToObject(typeof(Fruit), 3);
Console.WriteLine(foo.ToString()); //print "Grapes"
Console.WriteLine((int)foo); //print 3

C#

Leave a Reply