第7章继承和接口设计资料
例7.13】 分析以下程序的运行结果。 using System; using System.Collections; //新增 namespace Proj7_13 { class Program { class Stud { int xh; //学号 string xm; //姓名 int fs; //分数 public int pxh //pxh属性 { get { return xh; } } public string pxm //pxm属性 { get { return xm; } } public int pfs //pfs属性 { get { return fs; } } public Stud(int no, string name, int degree) { xh = no; xm = name; fs = degree; } public void disp() { Console.WriteLine(\t{0}\t{1}\t{2}, xh, xm, fs); } } public class myCompareClassxh : IComparer { int IComparer.Compare(object x, object y) { Stud a = (Stud)x; Stud b = (Stud)y; if (a.pxh b.pxh) return 1; else if (a.pxh == b.pxh) return 0; else return -1; } } public class myCompareClassxm : IComparer { int IComparer.Compare(object x, object y) { Stud a = (Stud)x; Stud b = (Stud)y; return String.Compare(a.pxm, b.pxm); } } public class myCompareClassfs : IComparer { int IComparer.Compare(object x, object y) { Stud a = (Stud)x; Stud b = (Stud)y; if (a.pfs b.pfs) return 1; else if (a.pfs == b.pfs) return 0; else return -1; } } static void disparr(ArrayList myarr, string str) { Console.W
原创力文档

文档评论(0)