OrderByメソッッド使用すると、データを昇順で並び替えることができます。
以下はnumbers配列の値を昇順で並び替えて、コンソールに出力する例です。
VBの例
Dim numbers() As Integer = {3, 5, 2, 1, 9, 8, 7}
For Each item As Integer In numbers.OrderBy(Function(n) n)
Console.WriteLine(item)
Next
C#の例
int[] numbers = { 3, 5, 2, 1, 9, 8, 7 };
foreach (var item in numbers.OrderBy(n => n))
{
Console.WriteLine(item);
}
また、OrderByDecendingメソッドを使用すると、データを降順で並べ替えることができます。
VBの例
Dim numbers() As Integer = {3, 5, 2, 1, 9, 8, 7}
For Each item As Integer In numbers.OrderByDescending(Function(n) n)
Console.WriteLine(item)
Next
C#の例
int[] numbers = { 3, 5, 2, 1, 9, 8, 7 };
foreach (var item in numbers.OrderByDescending(n => n))
{
Console.WriteLine(item);
}
Please follow and like us:

コメント