unity day 1

学习了基本语法,学了什么大概忘记了,做了什么也基本忘了。自学了集合吧

namespace un_lesson2_jihe
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            //集合-数组

        
            //堆存放变量,栈保留变量的地址

            ArrayList list = new ArrayList ();
            Student stu = new Student (10,"wangyi",1.2);
            Student stu1 = new Student (11, "xiaoer",2.5);
            Student stu2 = new Student (12, "xiaosan", 2.0);
//            list.Add (5);
//            list.Add (8);
//            list.Add (3);
//            list.Add (0);
            list.Add (stu);
            list.Add (stu1);
//            list.Add (stu2);
            //list.Add ("a");
            list.Sort ();
            //list.Reverse ();
            for (int i = 0; i < list.Count; i++) {
                Console.WriteLine (list[i]); 
            }
        }
    }

//通过接口编写自建类的对比方法
    public class Student:IComparable
    {
        public int CompareTo(object obj)
        {
            if (obj is Student) {
                Student s = (Student)obj;
                Console.WriteLine (this.Score);
                return this.Score.CompareTo (s.Score);
            } else {

                return 1;
            }

        }
//        public override string ToString ()
//        {
//            return "id:"+id+"\tname:"+name+"\tScore:"+Score;
//        } 


//重写自建类的ToString方法,得以直接输出到控制台
        public override string ToString ()
        {
            
            return string.Format ("[Student: id={0}, name={1}, Score={2}]", id, name, Score);
        }
        public int id{ get; set;}
        public string name{ get; set;}
        public double Score{ get; set;}
        public Student(int id,string name,double score)
        {
            this.id = id;
            this.name = name;
            this.Score = score;
        }
        public Student()
        {

        }
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值