日期:2014-05-17  浏览次数:20876 次

怎样给类成员动态赋值?100分送上!
        /// <summary>  
        /// 实现IComparable接口,用kcNum做比较  
        /// </summary>  
        /// <param name="obj">比较对象</param>  
        /// <returns>比较结果</returns>  
        public class KeChen : IComparable
        {
            public string kcName { get; set; }
            public int kcNum { get; set; }
            public int CompareTo(object obj)
            {
                if (obj is KeChen)
                {
                    return kcNum.CompareTo(((KeChen)obj).kcNum);
                }
                return 1;
            }
        }


……

           string strkc = "";
                //初始化课程类并排序  成绩提高最明显的课程  
            KeChen[] KC = new KeChen[] {
                new KeChen(){kcName="基础护理",kcNum=Convert.ToInt32( ds2.Tables[0].Rows[0][7])},
                new KeChen(){kcName="外科护理",kcNum=Convert.ToInt32( ds2.Tables[0].Rows[0][8])},
                new KeChen(){kcName="内科护理",kcNum=Convert.ToInt32( ds2.Tables[0].Rows[0][9])},
                new KeChen(){kcName="妇科护理",kcNum=Convert.ToInt32( ds2.Tables[0].Rows[0][10])},
                new KeChen(){kcName="儿科护理",kcNum=Convert.ToInt32( ds2.Tables[0].Rows[0][11])},
                new KeChen(){kcName="其它",kcNum=Convert.ToInt32( ds2.Tables[0].Rows[0][12])}};
 
                Array.Sort(KC);
                 Array.ForEach<KeChen>(KC, (m) =>
                    {
         &nb