多年来,我一直认为随着C# 中匿名类型的出现,例如:
// anon is compiled as an anonymous type
var anon = new { Name = "Terry", Age = 34 };
Linq to Sql 能够从结果集中构造匿名类型对象,例如:
示例(假设语法):
var activeUsers =
from u in ConnectionStrings:Northwind.Users
where u.IsActive = 1
select UserName, FullName, Email, Description
现在我可以对这个集合进行操作,例如:
foreach (var u in activeUsers)
{
AddToListView(u.UserName, u.FullName, u.Email);
}
这个简单、强大、易于使用的示例是幻想吗?