110,538
社区成员
发帖
与我相关
我的任务
分享
public class Student
{
public string Name { get; set;}
public string Code { get; set;}
public List<ClassMate> MateList { get; set;}
}
public class ClassMate
{
public string Name { get; set;}
public string Remark { get; set;}
public string Address { get; set;}
}
IEnumerable<IGrouping<string, ClassMate>> query = stu.MateList.GourpBy(g => g.Name, g => g);
public void Linq43()
{
List<Customer> customers = GetCustomerList();
var customerOrderGroups =
from c in customers
select
new
{
c.CompanyName,
YearGroups =
from o in c.Orders
group o by o.OrderDate.Year into yg
select
new
{
Year = yg.Key,
MonthGroups =
from o in yg
group o by o.OrderDate.Month into mg
select new { Month = mg.Key, Orders = mg }
}
};
ObjectDumper.Write(customerOrderGroups, 3);
}
stu.MateList.GroupBy(x => new { x.Name, x.Address })
var q = stu.MateList.GroupBy(x=>new{x.Name,x.Address}.Select(x => x.First())).ToList();
foreach(var item in q)
{
}
var q = stu.MateList.GroupBy(x => new { x.Name, x.Address }).Select(y => new { y.Key.Name, y.Key.Address, Count = y.Count() });
foreach (var item in q)
{
Console.WriteLine("Name: {0} Address: {1} Count: {2}", item.Name, item.Address, item.Count);
}
var q = stu.MateList.GroupBy(x=>new{x.Name,x.Address});
foreach(ClassMate item in q) //这里报错,不能强制转换类型..
{
}[/quote]