Is this Possible with Enum in C# ?

The enumeration in C# lets the developers to define a limited set of known values.

For example , I can define an enum called Designation as shown below use it in the application.

enum Designation
    {
        Trainee=1,
        SoftwareEngineer = 2,
        Consultant=3
    };

Now , Can i assign duplicate values to enum items ?

Is this Possible with Enum in C# ?

Yes , it is possible to assign duplicate values to the enumeration items . For example , imagine a scenario where  Software Engineers and Consultants needs to have the same value say 2 , below is a code snippet to demonstrate it.

enum Designation
    {
        Trainee=1,
        SoftwareEngineer = 2,
        Consultant=2
    };
If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Reply


x

Interesting BlogPosts to read

How to perform Shallow Copy in C# ? by @abundantcode
To perform Shallow copy in C# , you can use the this.MemberwiseClone() method. How to perform Shall...
How to add entries to ResourceDirectory in WPF using C# ?
Below is a sample code snippet demonstrating how the entries can be added to the ResourceDirectory i...
Replacing Multiple spaces with single space in C#
Are you looking at an sample demonstrating the usage of the regular expression to replace multiple s...