int[] a = new []{}; //放数组里边 int max = a[0] for(int i = 1; i<a.Length;i++) { if(max<a[i]) { max = a[i]; } } max就是最大值了
用linq int[] my = {1, 2, 3, 4}; int number = my.Max();
using System; using System.Collections.Generic; using System.Linq; using System.Text;namespace ConsoleApplication1 { class Program { static void Main(string[] args) { int[] numbers = new int[] { 1, 2, 3, 4, 5,9,8,7,6 }; Console.WriteLine(numbers.Max()); Console.ReadLine(); } } }
//放数组里边
int max = a[0]
for(int i = 1; i<a.Length;i++)
{
if(max<a[i])
{
max = a[i];
}
}
max就是最大值了
int[] my = {1, 2, 3, 4};
int number = my.Max();
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int[] numbers = new int[] { 1, 2, 3, 4, 5,9,8,7,6 };
Console.WriteLine(numbers.Max());
Console.ReadLine(); }
}
}