Reputation: 24592
I have a list:
public static List<PhraseSource> phraseSources;
The list has property:
public int? JishoJlpt { get; set; }
I am trying to get a count of the number of how many of each number of JishJlpt occur:
phraseSources.GroupBy(p => p.JishoJlpt)
.Select(g => new {
JishoJlpt g.Key,
Count: g.Count()
});
But it's giving me this error:
Can anyone help and give me advice on what might be wrong?
Upvotes: 0
Views: 41
Reputation: 3228
Looks like a syntax error. Anonymous objects use =
instead of :
This works for me:
List<int> list = new List<int>();
list.Add(1);
list.Add(1);
list.Add(3);
var items = list.GroupBy(p => p)
.Select(g => new {
Key = g.Key,
Count = g.Count()
});
Upvotes: 4