我想使用LINQ的功能,安装了.net framework 3.5. 
在vs2005中,新建了个项目,copy了下面的这些代码,提示有很多语法错误(我已经添加了引用,并用using 引入了命名空间)。 
我试验了一下在VS2008 express中,使用同样的代码,完全没有错误。 
请问,是由于2005的IDE的语法检查不兼容3.5的语法么?还是什么其它的原因? 
那我怎样才能在2005中使用framework3.5呢? 代码如下: 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Xml.Linq; namespace linqTest 

    class Student 
    { 
        public string First { get; set; } 
        public string Last { get; set; } 
        public int ID { get; set; } 
        public string Street { get; set; } 
        public string City { get; set; } 
        public List <int> Scores; 
    }     class Teacher 
    { 
        public string First { get; set; } 
        public string Last { get; set; } 
        public int ID { get; set; } 
        public string City { get; set; } 
    }     class XMLTransform 
    { 
        static void Main() 
        { 
            // Create the data source by using a collection initializer. 
            List <Student> students = new List <Student>() 
        { 
            new Student {First="Svetlana", Last="Omelchenko", ID=111, Scores = new List <int>{97, 92, 81, 60}}, 
            new Student {First="Claire", Last="O’Donnell", ID=112, Scores = new List <int>{75, 84, 91, 39}}, 
            new Student {First="Sven", Last="Mortensen", ID=113, Scores = new List <int>{88, 94, 65, 91}}, 
        };             // Create the query. 
            var studentsToXML = new XElement("Root", 
                from student in students 
                let x = String.Format("{0},{1},{2},{3}", student.Scores[0], 
                        student.Scores[1], student.Scores[2], student.Scores[3]) 
                select new XElement("student", 
                          new XElement("First", student.First), 
                          new XElement("Last", student.Last), 
                          new XElement("Scores", x) 
                        ) // end "student" 
                    ); // end "Root"             // Execute the query. 
            Console.WriteLine(studentsToXML);             // Keep the console open in debug mode. 
            Console.WriteLine("Press any key to exit."); 
            Console.ReadKey(); 
        } 
    } 
}

解决方案 »

  1.   

    那我怎样才能在2005中使用framework3.5呢? 好像不行,就像 2003 不能用 2.0 一样.个人观点.
      

  2.   

    这就是vs.net不如java的ide灵活的地方
      

  3.   

    public int ID { get; set; }public string Name { get; set; }public static void Main(){List<a> list = new List<a> { new a { ID = 1, Name = "wxd" }, new a { ID = 2, Name = "lzm" }, new a { ID = 3, Name = "wxwinter" } };var l1 = list.WxdWhere(le => le.Name == "lzm");// 上面的(Lambda表达式)等同于下面的(匿名方法)IEnumerable<a> l2 = list.WxdWhere(delegate(a le) { return le.Name == "lzm"; });//与调用系统Where一样var l3 = list.Where(le => le.Name == "lzm");}}public static class e{// 相关委托public delegate TResult Func<T, TResult>(T arg);//相关Where扩展方法//Func<TSource, bool>:接受一个类型为TSource的参数//Func<TSource, bool>:某个需要满足的条件,返回bool值public static IEnumerable<TSource> WxdWhere<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate){foreach (TSource item in source){if (predicate(item)){yield return item;}}}