public class Person
{
//当 lhs > rhs 的时候,就进行交换位置
public void SwapIfGreater<T>( ref T lhs, ref T rhs ) where T : System.IComparable<T>
{
T temp;
if ( lhs.CompareTo( rhs ) > 0 )
{
temp = lhs;
lhs = rhs;
rhs = temp;
}
}
}
class Program
{
static void Main( string[ ] args )
{
Person p = new Person( );
int a=5;
int b=3;
p.SwapIfGreater<int>( ref a, ref b );
Console.WriteLine( "a= {0} b={1}",a,b);
}
}