Core C#

Enums with Repeated Values

This C# program demonstrates how to program with enums that have repeated values in C#.

Program.cs

using System;

namespace Enumerations2 {

    enum EGears {
        keReverse = -1,
        kePark,
        keNeutral = kePark,
        keDrive,
        keLow = keDrive
    }

    class Program {
        static void Main(string[] args) {
            Console.WriteLine("The values of EGears are:");
            Console.WriteLine(String.Format("EGears.keReverse has the value {0}", (int)EGears.keReverse));
            Console.WriteLine(String.Format("EGears.kePark has the value {0}", (int)EGears.kePark));
            Console.WriteLine(String.Format("EGears.keNeutral has the value {0}", (int)EGears.keNeutral));
            Console.WriteLine(String.Format("EGears.keDrive has the value {0}", (int)EGears.keDrive));
            Console.WriteLine(String.Format("EGears.keLow has the value {0}", (int)EGears.keLow));
            Console.WriteLine("\n");
        }
    }
}
 

Output

The values of EGears are:
EGears.keReverse has the value -1
EGears.kePark has the value 0
EGears.keNeutral has the value 0
EGears.keDrive has the value 1
EGears.keLow has the value 1


Press any key to continue . . .
 
 

© 2007–2025 XoaX.net LLC. All rights reserved.