在.NET2.0中使用LINQ

.net2.0中可否使用linq?

可以。

在网上找了下相关资源,找到2个方法

1.使用LinqBridge(google一下,资料很多)

2.使用微软的.NET3.5下的System.Core.dll,毕竟是微软自己的东西,应该靠谱。因为.NET3.5是在.NET2.0基础上的一个扩展,按说,.NET3.5的程序集应该都能运行在.net2.0上。如下是我尝试过程:

2.1打开VS2010(或者VS2008),新建一个.NET2.0的项目

2.2添加 System.Core.dll 3.5 的引用,位置在C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\Client\System.Core.dll(注意:在你的机器上可能不是这里);把这个引用程序集的【复制本地】属性改为True(这里是为了把System.Core.dll 署到目标机器(目标机器环境是.NET2.0)上)

2.3使用LINQ

using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace UseLinqInNet2
{
    class Program
    {
        static void Main(string[] args)
        {
            var mydatas = new int[] { 2345819921946 };

            var q = from i in mydatas where i < 30 select i;

            foreach (var i in q)
            {
                Console.Write(string.Format("\t{0}", i));
            }
            Console.WriteLine();

            Console.ReadLine();
        }
    }
}

 

3.运行通过

 

/Files/mll5644/UseLinqInNet2.7z

 

 

 

 

 

posted @ 2012-11-23 14:29  老农民5644  阅读(2926)  评论(1编辑  收藏  举报