using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
namespace practise_1
{
class Program
{
class Person:IComparable
{
public int age;
public Person(int _age)
{
age = _age;
}
public override string ToString()
{
return age + "";
}
public int CompareTo(object obj)
{
if (obj is Person)
{
Person anotherPerson = obj as Person;
return age - anotherPerson.age;
}
return 0;
}
}
static void Main(string[] args)
{
ArrayList list = new ArrayList();
list.Add(new Person(0));
list.Add(new Person(10));
list.Add(new Person(7));
list.Add(new Person(50));
list.Add(new Person(500));
list.Add(new Person(20));
list.Add(new Person(3));
list.Add(new Person(100));
list.Add(new Person(99));
list.Add(new Person(19));
list.Sort();
foreach(var l in list)
{
Console.WriteLine(l);
}
Console.ReadKey();
}
}
}
C#比较类的大小
最新推荐文章于 2024-03-20 20:45:15 发布