c#枚举数字转枚举
using System;
class program
{
enum emp_salary : int
{
emp1,
emp2,
emp4
}
static void Main(string[] args)
{
int sal = (int)emp_salary.emp2;
Console.WriteLine(sal);
}
}
Correct answer: 2
1
The above code will print "1" on console screen.
using System;
class program
{
enum emp_salary : int
{
emp1,
emp2,
emp3
}
static void Main(string[] args)
{
emp_salary.emp1 = 10;
Console.WriteLine(emp_salary.emp2);
}
}
Correct answer: 3
Syntax error
The above code will generate syntax error because the left-hand side must be a variable.
using System;
class program
{
enum emp_salary : int
{
emp1,
emp2,
emp3
}
static void Main(string[] args)
{
emp_salary emp = emp_salary.emp3;
Console.WriteLine(emp.GetType());
}
}
Correct answer: 4
program+emp_salary
The above will class name with enum name.
protected Color { Red=1, Green=2};
Correct answer: 1
Yes
Yes, we can create an enum with a protected modifier.
private Color { Red=1, Green=2};
Correct answer: 1
Yes
Yes, we can create an enum with a private modifier.
c#枚举数字转枚举