typeOf,简单来说就是:获取指定类的类对象
namespace DotNetCoreSimple2
{
class Program
{
static void Main(string[] args)
{
Student student = new Student()
{
No = "201707020202",
Name = "杨风",
Sex = Sex.男,
Role = Role.普通用户 | Role.系统管理员
};
Console.WriteLine(student);
//typeOf获取指定类的类对象
bool isDefined = Enum.IsDefined(**typeof(**Sex), "男");
Sex sex = (Sex)Enum.Parse(**typeof**(Sex), "男");
string name = Enum.GetName(**typeof**(Sex), 2);
}
}
**public enum Sex { 男 = 1, 女 = 2 }**
public enum Role
{
普通用户 = 1,
系统管理员 = 2,
超级管理员 = 4
}
public class Student
{
public string No { get; set; }
public string Name { get; set; }
public Sex Sex { get; set; }
public Role Role { get; set; }
public override string ToString()
{
return $"学号:{No}\n姓名:{Name}\n性别:{Sex}";
}
}
}