码迷,mamicode.com
首页 > 其他好文 > 详细

按顺序比较大小

时间:2016-01-15 23:11:27      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:

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;

        }
    }
}

  

按顺序比较大小

标签:

原文地址:http://www.cnblogs.com/xh0626/p/5134633.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!