您的位置:首页 > 其它

按顺序比较大小

2016-01-15 22:16 375 查看
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;

}
}
}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: