how a derived class may override an existing enumeration in a base class
/*
C# Programming Tips & Techniques
by Charles Wright, Kris Jamsa
Publisher: Osborne/McGraw-Hill (December 28, 2001)
ISBN: 0072193794
*/
//
// BaseEnum.cs - Demonstrates how a derived class may override an existing
// enumeration in a base class
//
// Compile this program with the following command line:
// C:>csc baseenum.cs
//
namespace nsEnum
{
using System;
public class clsBaseClass
{
// Define the enum type
public enum Weekdays
{
Sun, Mon, Tues, Wed, Thurs, Fri, Sat
}
static public void Main ()
{
Console.WriteLine ("In base class, Sunday = " +
(int) Weekdays.Sun);
clsNewClass second = new clsNewClass();
second.ShowEnum ();
}
}
class clsNewClass : clsBaseClass
{
public new enum Weekdays
{
Sun = 1, Mon, Tues, Wed, Thurs, Fri, Sat
}
public void ShowEnum()
{
// Use the class name with the enum name
Console.WriteLine ("In derived class, Sunday = " +
(int) Weekdays.Sun);
}
}
}
Related examples in the same category