C# struct 和 enum

//构造函数
struct Person
{
//访问修饰符
public int age; // 公开
private string name; // 私有
internal string fname; // 命名空间内可用
protected string lname; // 继承可用
}
//调用方法
Person person = new Person();
person.age = 10;
Console.WriteLine(Person.age);
//枚举类型
enum day { Monday, Tuesday, Wenesday, Thursday, Friday, Saturday, Sunday}

//调用方法
var day = Day.Monday;
Console.WriteLine(day);
Console.WriteLine(int(day));//int 后默认从0开始
enum day { Monday = 1 , Tuesday, Wenesday, Thursday, Friday, Saturday, Sunday}//强制从1开始

发表回复

登录... 后才能评论