どうも、ちょげ(@chogetarou)です。
配列の最大値を取得する方法を紹介します。
方法

配列の最大値を取得するには、Maxを使います。
まず、System.Linqを取り入れます。
using System.Linq;
そして、配列からMaxメソッドを呼び出します。
array.Max();
Maxメソッドは、呼び出した配列の最大値を返します。
使用例
using System;
using System.Linq;
public class Sample{
public static void Main(){
int[] numbers = new int[] { 1, 1, 3, 10, 4, 5 };
int max = numbers.Max();
Console.WriteLine(max); //10
}
}
コメント