public interface System.IComparable { int CompareTo(object o); }
public class TestCls: IComparable { public TestCls() { } private int _value; public int Value { get { return _value; } set { _value = value; } } public int CompareTo(object o) { //使用as模式进行转型判断 TestCls aCls = o as TestCls; if (aCls != null) { //实现抽象方法 return _value.CompareTo(aCls._value); } } }
abstract public class Animal { //定义静态字段 static protected int _id; //定义属性 public abstract static int Id { get; set; } //定义方法
public abstract void Eat(); //定义索引器 public string this[int i] { get; set; }
/// /// 实现抽象类 ///
public class Dog: Animal { public static override int Id { get {return _id;} set {_id = value;} } public override void Eat() { Console.Write("Dog Eats.") } }