Types are listed in C #

I read this expression in a C # book.

Enumerations do not have to follow a sequential order and should not have unique values .

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

1.

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

2.

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

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

+5
source share
5 answers

1 is correct, 2 is not.

As the book says, enumerations should not have unique values ​​(Example 2 shows enumerations with unique names). Names must be unique, as the compiler maps it to a value.

+3
source

, Values Names

+4

- :) System.Enum( ), , - , , # 1 , # 2 .

+3

1 . 2 . . .

, , . , . -, , , / . :

public enum PersonnelLevels
{   
    Management=0,
    Sales=1,
    IT=1
}  
+1

enum ( #):

- int.

. . .

, . .

0

All Articles