using System;
namespace EnumProject
{
public enum MicrosoftOffice
{
Word = 0,
Excel = 1,
Powerpoint = 3,
Visio = 5,
}
class Program
{
static void Main(string[] args)
{
TryParseEnum();
}
/// <summary>
/// This is used to check and get value of specified string.
/// </summary>
private static void TryParseEnum()
{
MicrosoftOffice msDefault = MicrosoftOffice.Powerpoint;
//Supplying correct enum string.
bool ms = Enum.TryParse("Word", true, out msDefault);
Console.WriteLine(ms.ToString() + " " + msDefault.ToString());
MicrosoftOffice msDefault1 = MicrosoftOffice.Powerpoint;
//Supplying wrong enum string.
bool ms1 = Enum.TryParse("xcel", out msDefault1);
Console.WriteLine(ms1.ToString() + " " + msDefault1.ToString());
}
}
}