像这样的东西?
var list = new List<MyClass>(new[] {
new MyClass { Date = DateTime.Parse("01/01/2011"), Username = "james" },
new MyClass { Date = DateTime.Parse("01/01/2011"), Username = "james" },
new MyClass { Date = DateTime.Parse("01/01/2011"), Username = "alex" },
new MyClass { Date = DateTime.Parse("01/01/2011"), Username = "james" },
new MyClass { Date = DateTime.Parse("02/01/2011"), Username = "matt" },
new MyClass { Date = DateTime.Parse("02/01/2011"), Username = "jamie" },
new MyClass { Date = DateTime.Parse("02/01/2011"), Username = "alex" },
new MyClass { Date = DateTime.Parse("02/01/2011"), Username = "james" },
new MyClass { Date = DateTime.Parse("02/01/2011"), Username = "james" },
new MyClass { Date = DateTime.Parse("02/01/2011"), Username = "lucy" },
new MyClass { Date = DateTime.Parse("02/01/2011"), Username = "alex" },
new MyClass { Date = DateTime.Parse("03/01/2011"), Username = "james" },
new MyClass { Date = DateTime.Parse("03/01/2011"), Username = "bob" },
new MyClass { Date = DateTime.Parse("03/01/2011"), Username = "bob" },
new MyClass { Date = DateTime.Parse("03/01/2011"), Username = "james" },
new MyClass { Date = DateTime.Parse("03/01/2011"), Username = "james" },
new MyClass { Date = DateTime.Parse("04/01/2011"), Username = "alex" },
new MyClass { Date = DateTime.Parse("04/01/2011"), Username = "alex" },
new MyClass { Date = DateTime.Parse("04/01/2011"), Username = "alex" }
});
list.GroupBy(l => l.Date, l => l.Username)
.Select(g => new {
Date = g.Key,
Count = g.Distinct().Count()
});