c#类的继承与包含的关系

基础例子

class Dept
{
private string name;
private Emp emp;

 
 

public string getName()
{
return this.name;
}

 
 

public void setName(string name)
{
this.name = name;
}

 
 

public Emp getEmp()
{
return this.emp;
}

 
 

public void setEmp(Emp emp)
{
this.emp = emp;
}

 
 


}

 
 

class Emp
{
private string name;
private string six;
private double tel;
private Auth auth;

 
 

public string getName()
{
return this.name;
}

 
 

public void setName(string name)
{
this.name = name;
}

 
 


public string getsix()
{
return this.six;
}
public void setSix(string six)
{
this.six = six;
}

 
  
 
 
 

public void setTel(double tel)
{
this.tel = tel;
}
public double getTel()
{
return this.tel;
}

 
 


public void setAuth(Auth auth)
{
this.auth = auth;
}

 
 

public Auth getAuth()
{
return this.auth;
}

 
  
 
 
 

}

 
 

class Auth
{
private int x;
private int y;

 
 

public void setX(int x)
{
this.x = x;
}

 
 

public int getX()
{
return this.x;
}

 
  
 
 
 

public void setY(int y)
{
this.y = y;
}

 
 

public int getY()
{
return this.y;
}
}

 
 

class Program
{

 
  
 
 
 

static void Main(string[] args)
{
//哪个部门里的哪个人有哪些权限

 
 

Auth auth1 = new Auth();

 
 

auth1.setX(1);

 
 

Auth auth2 = new Auth();
auth1.setX(1);
auth2.setY(2);

 
 

Emp zhangsan = new Emp();
zhangsan.setName("zhangsan");
zhangsan.setSix("nan");
zhangsan.setTel(21321315);
zhangsan.setAuth(auth1);

 
 

Dept it = new Dept();
it.setName("it");
it.setEmp(zhangsan);
string dept = it.getName();
Console.WriteLine("部门:" + it.getName() + "员工:" + it.getEmp().getName() + "权限" + it.getEmp().getAuth().getX());

 
  
 
 
 

Console.WriteLine("hello word");
Console.ReadLine();
}

进阶例子

namespace
sqlgx { class Dept { private int deptid; private String deptname; private ArraySegment<User> userarray; public void setdeptid(int deptid) { this.deptid = deptid; } public int getdeptid() { return this.deptid; } public void setdeptname(string deptname) { this.deptname = deptname; } public string getdeptname() { return this.deptname; } } class User { private int userid; private string username; private int password; private ArraySegment<Auth> autharray; private ArraySegment<Manue1> manue1array; public void setuserid(int userid) { this.userid = userid; } public int getuserid() { return this.userid; } public void setusername(string username) { this.username = username; } public string getusername() { return this.username; } public void setpassword(int password) { this.password = password; } public int getpassword() { return this.password; } } class Auth { private int authid; private int authadd; private int authdel; private int authupdate; public void setauthid(int authid) { this.authid = authid; } public int getauthid() { return this.authid; } public void setauthadd(int authadd) { this.authadd = authadd; } public int getauthadd() { return this.authadd; } public void setauthdel(int authdel) { this.authdel = authdel; } public int getauthdel() { return this.authdel; } public void setauthupdate(int authupdate) { this.authupdate = authupdate; } public int getauthupdate() { return this.authupdate; } } class Manue1 { private int manue1id; private string manue1name; private ArraySegment<Manue2> manue2array; public void setmanue1id(int manue1id) { this.manue1id = manue1id; } public int getmanue1id() { return this.manue1id; } public void setmanue1name(string manue1name) { this.manue1name = manue1name; } public string getmanue1name() { return this.manue1name; } } class Manue2 { private int manue2id; private string manue2name; public void setmanue2id(int manue2id) { this.manue2id = manue2id; } public int getmanue2id() { return this.manue2id; } public void setmanue2name(string manue2name) { this.manue2name = manue2name; } public string getmanue2name() { return this.manue2name; } } class MainTest { /* static void Main(string[] args) { //创建it部门 //创建用户 Program p = new Program(); string sql = "SELECT *FROM dept,abc.`user` WHERE dept.`deptid`=1 AND abc.`user`.`deptid`=dept.deptid"; p.getUserData(sql); Console.WriteLine("hello world"); Console.ReadLine(); }*/ }

猜你喜欢

转载自www.cnblogs.com/DGJS/p/10208989.html