类的声明:
public enum Gender
{
男,女
}
class Myclass
{
public string _name;
public int _age;
public string _department;
public Gender _gender;
public void write()
{
System.Diagnostics.Debug.Write("我的姓别{0}"+_gender);
}
}
类的调用:
Myclass myClass = new Myclass();
myClass._gender = Gender.男;
myClass.write();
类的构造函数和使用
public enum Gender
{
男,女
}
class Myclass
{
private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}
private Gender _gender;
public Gender Gender
{
get { return _gender; }
set { _gender = value; }
}
private int _age;
public int Age
{
get { return _age; }
set { _age = value; }
}
private string _department;
public string Department
{
get { return _department; }
set { _department = value; }
}
public void write()
{
System.Diagnostics.Debug.WriteLine("我的姓别{0},我的性别{1},我的年龄{2},我的部门{3}", this.Name, this.Gender, this.Age, this.Department);
}
public Myclass(string name,Gender gender,int age,string department)
{
this.Name = name;
this.Gender = gender;
this.Age = age;
this.Department = department;
}
}
构造函数的调用:
Myclass myClass = new Myclass("张三", Gender.男, 15, "开发部");
myClass.write();
类的继承:
class 类的继承:Myclass
{
private int _salTarget;
public int SalTarget
{
get { return _salTarget; }
set { _salTarget = value; }
}
public 类的继承(string name, int age, int saltarget) : base (name,age )
{
// this.Name = name;
//this.Age = age;
this.SalTarget = saltarget;
}
public void write()
{
System.Diagnostics.Debug.WriteLine("销售目标{0},我的姓名{1},我的年龄{2}", this.SalTarget, this.Name, this.Age);
}
}
继承类的调用:
类的继承 myLei = new 类的继承("张三", 15,2500);
myLei.write();