Examples:
public enum nums { zero, one, two, three, four, five, six, seven, eight, nine, teen };
- enum: A keyword which denotes enum type
- nums: This is a type which has defined elements (such as zero, one....)
- {zero, one ...} are elements which has the underlying type of each element (such as int, string, long...) . By default, whose type is int
class Program
{
enum nums { zero, one, two, three, four, five, six, seven, eight, nine, teen };
static void Main(string[] args)
{
nums da = nums.one ;
da = increment(da);
Console.WriteLine(da);
Console.ReadKey();
}
private static nums increment(nums pnums)
{
if (pnums == nums.eight)
return pnums;
else
return pnums+1;
}
private static nums decrement(nums pnums)
{
if (pnums == nums.one)
return pnums;
else
return pnums - 1;
}
}
{
enum nums { zero, one, two, three, four, five, six, seven, eight, nine, teen };
static void Main(string[] args)
{
nums da = nums.one ;
da = increment(da);
Console.WriteLine(da);
Console.ReadKey();
}
private static nums increment(nums pnums)
{
if (pnums == nums.eight)
return pnums;
else
return pnums+1;
}
private static nums decrement(nums pnums)
{
if (pnums == nums.one)
return pnums;
else
return pnums - 1;
}
}
0 comments:
Post a Comment