我想使用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中,新建了个项目,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();
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货