C#使用linq查询大数据集的方法

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LargeNumberQuery
{
  class Program
  {
    static void Main(string[] args)
    {
      int[] numbers = CreateNumbers(7384738);
      Console.WriteLine("Numbers less than 2000:");
      var queryResults =
        from n in numbers
        where n < 2000
        select n;   
      foreach (var item in queryResults)
      {
        Console.WriteLine(item);
      }
      Console.ReadLine();
    }
    private static int[] CreateNumbers(int count)
    {
      Random generator = new Random(0);
      int[] result = new int[count];
      for (int i = 0; i < count; i++)
      {
        result[i] = generator.Next();
      }
      return result;
    }
  }
}

 希望本文所述对大家的C#程序设计有所帮助。

上一篇:【Android开发】网络编程及Internet应用-通过HTTP访问网络


下一篇:ASP.NET Web开发 Echarts图表空数据优化