我遇到了我应该使用的LINQ查询问题。使用LINQ查询对数组进行排序
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LinqIntegersDemo.cs
{
class Program
{
static void Main(string[] args)
{
int[] nums = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
// var sorted = from n in nums orderby n ascending select n;
int x = 0;
foreach (var n in nums)
{
Console.Write("Enter an integer >> ");
nums[x] = Convert.ToInt32(Console.ReadLine());
++x;
}
var sorted = from n in nums orderby n ascending select n;
foreach (var n in nums)
{
Console.WriteLine(n);
}
Console.ReadLine();
}
}
}
我已经浏览了MSDN和我在那里看到的代码片段告诉我,我写了我的查询正确。那么为什么数组不按升序排序,这是我需要发生的事情。
二的foreach没有使用可变的 “排序” – Measuring
你想的foreach(在排序的变种N) – CooncilWorker