你可以参考,arraylist.sort 排序
[ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
public static void Sort(Array keys, Array items, int index, int length, IComparer comparer)
{
if (keys == null)
{
throw new ArgumentNullException("keys");
}
if ((keys.Rank != 1) || ((items != null) && (items.Rank != 1)))
{
throw new RankException(Environment.GetResourceString("Rank_MultiDimNotSupported"));
}
if ((items != null) && (keys.GetLowerBound(0) != items.GetLowerBound(0)))
{
throw new ArgumentException(Environment.GetResourceString("Arg_LowerBoundsMustMatch"));
}
if ((index < keys.GetLowerBound(0)) || (length < 0))
{
throw new ArgumentOutOfRangeException((length < 0) ? "length" : "index", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
}
if (((keys.Length - (index - keys.GetLowerBound(0))) < length) || ((items != null) && ((index - items.GetLowerBound(0)) > (items.Length - length))))
{
throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen"));
}
if ((length > 1) && (((comparer != Comparer.Default) && (comparer != null)) || !TrySZSort(keys, items, index, (index + length) - 1)))
{
object[] objArray = keys as object[];
object[] objArray2 = null;
if (objArray != null)
{
objArray2 = items as object[];
}
if ((objArray != null) && ((items == null) || (objArray2 != null)))
{
new SorterObjectArray(objArray, objArray2, comparer).QuickSort(index, (index + length) - 1);
}
else
{
new SorterGenericArray(keys, items, comparer).QuickSort(index, (index + length) - 1);
}
}
}
internal void QuickSort(int left, int right)
{
do
{
int low = left;
int hi = right;
int median = Array.GetMedian(low, hi);
this.SwapIfGreaterWithItems(low, median);
this.SwapIfGreaterWithItems(low, hi);
this.SwapIfGreaterWithItems(median, hi);
object y = this.keys[median];
do
{
try
{
while (this.comparer.Compare(this.keys[low], y) < 0)
{
low++;
}
while (this.comparer.Compare(y, this.keys[hi]) < 0)
{
hi--;
}
}
catch (IndexOutOfRangeException)
{
throw new ArgumentException(Environment.GetResourceString("Arg_BogusIComparer", new object[] { y, y.GetType().Name, this.comparer }));
}
catch (Exception exception)
{
throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), exception);
}
catch
{
throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"));
}
if (low > hi)
{
break;
}
if (low < hi)
{
object obj3 = this.keys[low];
this.keys[low] = this.keys[hi];
this.keys[hi] = obj3;
if (this.items != null)
{
object obj4 = this.items[low];
this.items[low] = this.items[hi];
this.items[hi] = obj4;
}
}
low++;
hi--;
}
while (low <= hi);
if ((hi - left) <= (right - low))
{
if (left < hi)
{
this.QuickSort(left, hi);
}
left = low;
}
else
{
if (low < right)
{
this.QuickSort(low, right);
}
right = hi;
}
}
while (left < right);
}
public int getMax(int[] ints)
{
int Max = ints[0];
for (int i = 1; i < ints.Length; i++)
{
Max = Math.Max(Max, ints[i]);
}
return Max;
}
//ints为传入的要比较的数字的数组.除了整数外,还可自己将本方法改为其它数据类型的比较,此法支持N个数中找最大值
using System;
class Bijiao
{
static void Main()
{
int s1;
int s2;
int s3;
Console.WriteLine("请输入第一个数字:");
s1=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("请输入第二个数字:");
s2=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("请输入第三个数字:");
s3=Convert.ToInt32(Console.ReadLine());
if(s1>s2)
{
if(s1>s3)
{
Console.WriteLine(s1);
}
else
{
Console.WriteLine(s3);
}
}
else
{
if(s2>s3)
{
Console.WriteLine(s2);
}
else
{
Console.WriteLine(s3);
}
}
}
}
最笨的方法一个个比
int a = 5;
int b = 6;
int c = 33;
int d;
d = a;
if (b > d)
d = b;
if (c > d)
d = c;
static void main()
{
//比3个
int max = Max(Max(1,2),Max(2,3));
//比4个
int max = Max(Max(1,2),Max(3,4));
}
public int Max(int x,int y){
return (x>y?x:y);
}