class Program
{
static void Main(string[] args)
{
Struct[] array = new Struct[3];
array[0] = new Struct();
array[0].A = 4;
array[0].B = "1";
array[1] = new Struct();
array[1].A = 3;
array[1].B = "2";
array[2] = new Struct();
array[2].A = 5;
array[2].B = "3";
Array.Sort(array, new MyComparer());
foreach (Struct s in array)
{
Console.WriteLine("{0},{1}", s.A, s.B);
}
Console.ReadKey();
}
public struct Struct
{
public int A;
public string B;
}
public class MyComparer : IComparer<Struct>
{
#region IComparer<Struct> 成员
int IComparer<Struct>.Compare(Struct x, Struct y)
{
return x.A - y.A;
}
#endregion
}
}