
The enum is used to declare a list of named integer constants. It can be defined using the enum keyword directly inside a namespace, class, or structure. The enum is used to give a name to each constant so that the constant integer can be referred using its name.
Enum method Name:
• Format
• GetName
• GetNames
• GetValues
• object Parse(type, string)
• bool TryParse(string, out TEnum)
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Reflection;
using testForClass1;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
namespace testFor
{
enum WeekDays
{
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday,
Sunday
}
public class Students
{
static void Main(string[] args)
{
Console.WriteLine(Enum.GetName(typeof(WeekDays), 4));
Console.WriteLine("*--------*");
foreach (var oneByOne in Enum.GetNames(typeof(WeekDays)))
{
Console.WriteLine(oneByOne.ToString());
}
Console.Read();
}
}
}
We can see the Enum name is WeekDays. First print the single value of this Enum index is 4. One The Other Hand print the each value of the enum Using the ForEach Loop. We can see the out put on the console window.