Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

enum types in C#

Tags:

c#

enums

I read this statement in a C# book.

Enumerations do not necessarily need to follow a sequential ordering, and need not have unique values.

If I understand that statement, it means one of this is acceptable (I don't know which):

1.

enum EmpType
{
    Manager = 1,
    Grunt = 1,
    Contractor = 100,
    VicePresident = 9
}

2.

enum EmpType
{
    Manager = 10,
    Manager = 1,
    Contractor = 100,
    VicePresident = 9
}

Can someone please explain to me? I thought C# was supposed to be a subset of C/C++.

like image 543
afaolek Avatar asked Jun 08 '11 10:06

afaolek


1 Answers

The first one would be valid, you may have duplicate Values not duplicate Names

like image 185
Richard Friend Avatar answered Oct 05 '22 05:10

Richard Friend