按顺序比较大小

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication11
{
    class Program
    {
        static void Main(string[] args)
        {

            Petss[] pet = new Petss[]{
            new Petss(){name="张三",age=110},
            new Petss(){name="张1三",age=11},
            new Petss(){name="张2三",age=40}
            };
            Array.Sort(pet);
            foreach (var item in pet)
            {
                Console.WriteLine(item.age);
            }

            Console.ReadKey();

            int[] arr = { 1, 2, 3, 4, 5 };
            //  arr.OrderBy()
            // arr.OrderBy

        }
    }


    class Petss : IComparable
    {

        public int age { set; get; }
        public string name { set; get; }


        public int CompareTo(object obj)
        {
            Petss p = (Petss)obj;
            return p.age - this.age;

        }
    }
}

  

posted @ 2016-01-15 22:16  刀小爱  阅读(243)  评论(0编辑  收藏  举报