我收到此错误:System.Linq.Enumerable + WhereSelectListIterator 2[ConsoleApplication1.Person,<>f_
_AnonymousType0
2 [System.String,System.String]]
当我尝试在控制台应用程序中执行此操作时:
public class Person
{
public int ID;
public int IDRole;
public string FirstName;
public string LastName;
}
class Program
{
static void Main(string[] args)
{
List<Person> people = new List<Person> {
new Person() {ID = 1, IDRole = 1, LastName= "Anderson",
FirstName = "Brad"},
new Person() {ID = 2, IDRole = 2, LastName= "Gray",
FirstName = "Tom"}
};
var query = from p in people
where p.ID == 1
select new { p.FirstName, p.LastName };
Console.Write( query);
Console.ReadLine();
}}
答案 0 :(得分:2)
您需要迭代查询
foreach(var q in query)
{
Console.Write( string.Format("{0} {1}",new []{ q.FirstName ,q.LastName }));
}
Console.ReadLine();