正在加载图片...
IComparable接口 /实现IComparable接▣的CompareTo方法 public int CompareTo(Object obj) { if (!Stydentteobj as Student; thrwgumentException(“参数必须为Student 类的廓础身常 return this.name.CompareTo(s.name ) Student st=(Student)obj; return this.name.CompareTo(st.name ) 3 3 IComparable接口 什么是接口 接口的声明 接口成员 接口的实现 一系列需要实现的功能的定义 [接口修饰符] interface 接口名 [: 基接口] { 接口体; } int CompareTo (Object obj); class Student : IComparable //实现IComparable接口的CompareTo方法 public int CompareTo ( Object obj) { } if (!(obj is Student) { throw new ArgumentException (“参数必须为Student 类的实例"); } Student st= (Student) obj; Student s = obj as Student; if(s == null) //抛出异常 return this.name.CompareTo(s.name ); return this.name.CompareTo(st.name );
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有