07 2012 档案
已知有Employee类,内有2属性:salary和EmployeeCollection(第二个是一个集合,存储其直接下属)。
摘要:递归方法 :decimal Salary(Employee e) { decimal s = e.salary; if (e.EmployeeCollection !=null) { foreach (Employee x in e.EmployeeCollection) { s += Salary(x); } } return s; } 阅读全文
posted @ 2012-07-20 14:59 热爱工作 阅读(123) 评论(0) 推荐(0)
继承与重写例子
摘要:using System;class A{public A(){PrintFields();}public virtual void PrintFields(){}}class B:A{int x=1;int y;public B(){y=-1;}public override void PrintFields(){Console.WriteLine("x={0},y={1}",x,y);}当使用new B()创建B的实例时,产生什么输出?A a=new B();答案1,0B b =new B(); 答案1,0 阅读全文
posted @ 2012-07-20 14:32 热爱工作 阅读(127) 评论(0) 推荐(0)