This simple C# enum example will help you to understand that how enum works. Enums are basically use to create numeric constants in C#. Like in below example you can see the how enums are compared using the name. Enums are value type so stored in stack. you can convert enums to numeric value also using the casting.
Enums Example:
using System;
namespace MyApp
{
class clsCopyArray
{
enum Software_life
{
Software_testing,
Software_development,
Project_management
};
static void Main(string[] args)
{
Software_life my_var = Software_life.Software_development;
Console.WriteLine(my_var);
if (my_var == Software_life.Project_management)
{
Console.WriteLine("Not Same");
}
else if (my_var == Software_life.Software_development)
{
Console.WriteLine("Same");
}
Console.ReadLine();
}
}
}
0 comments:
Post a Comment