日期:2014-05-20  浏览次数:20711 次

可以在vs2005中使用.net framework 3.5么?
我想使用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();
  }
  }


}

------解决方案--------------------
vs2005无法
------解决方案--------------------
.Net 3.5 内包括了 .Net 1.1, .Net 2.0 , .Net 3.0 和 .Net 3.5

但是 vs2005 只支援到 .Net 2.0 而已,你的代码内有 .Net 3.5 的新功能 (System.Xml.Linq 和 System.Linq),

所以 vs2005 会给错。

------解决方案--------------------
不行,只能在.net2008中用
------解决方案--------------------
用VS2008吧
------解决方案--------------------
linq的新语法是要新的编译器才能支持的。