如何在C#中,求已知10个元素中的最大值和最小值

来源:百度知道 编辑:UC知道 时间:2024/09/22 06:44:39
如题
具体的代码给个

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int[] arr ={1,2,3,4,5,6,7,8,9,10};
int max, min,i;
max = arr[1];
min = arr[2];
for (i = 0; i < 10; i++)
{
if (max < arr[i])
{
max = arr[i];
}
else if (min > arr[i])
{
min = arr[i];
}

}
Console.WriteLine("{0},{1}", max, min);
}
}
}

For .Net3.5,3.0

using System.Linq;

int[] arr = new int[] { 8, 5, 89, 3, 56, 4, 1, 58 };
var m = from n in arr orderby n select n;

label1.Text = &qu