摘要:
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace InheritanceApp{ class Employee { public string name; public Employee(string name) { this.name = name; } public virtual void CalculatePay() { Console.WriteLine("Employee.CalculatePay called for {0}", 阅读全文
posted @ 2011-03-09 22:43
焦涛
阅读(305)
评论(0)
推荐(0)
摘要:
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace InheritanceApp{ class Employee { public string name; public Employee(string name) { this.name = name; } public void CalculatePay() { Console.WriteLine("Employee.CalculatePay called for {0}",name); } 阅读全文
posted @ 2011-03-09 21:29
焦涛
阅读(875)
评论(0)
推荐(0)
摘要:
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace InheritanceApp{ class Employee { public void CalculatePay() { Console.WriteLine("Employee.CalculatePay()"); } } class SalariedEmployee : Employee { //如果去掉new出现如下警告 //警告:“InheritanceApp.SalariedEmplo 阅读全文
posted @ 2011-03-09 20:46
焦涛
阅读(755)
评论(0)
推荐(0)
摘要:
using System;using System.Collections.Generic;using System.Linq;using System.Text;//封闭类不能派生子类//原因:封闭类不能被作为基类使用//好处:防止意外的派生的操作//注意:抽象类不能作为封闭类使用(抽象类本质决定了他们必须被作为基类使用)namespace InheritanceApp{ sealed class Point { public Point(int x, int y) { X = x; Y = y; } public int X; public int Y; } //语法错误:无法从密封类型P 阅读全文
posted @ 2011-03-09 19:51
焦涛
阅读(1973)
评论(0)
推荐(0)
摘要:
//继承 //1.C#中实现多继承效果的唯一办法是通过使用接口 class Control { } interface ISerializable { } interface IDataBound { } //MyFancyGrid继承自Control实现了ISerializable和IDataBound接口 class MyFancyGrid : Control, ISerializable, IDataBound { } 下面做法是错误的。 阅读全文
posted @ 2011-03-09 19:41
焦涛
阅读(562)
评论(0)
推荐(0)
浙公网安备 33010602011771号