I am facing an issue with counting the number of occurrences by date in C#. Should I use Linq to filter it? Please advise. Thank you.
Date | Player ID |
---|---|
1/1/2001 | 23 |
1/1/2001 | 29 |
1/1/2001 | 24 |
3/1/2001 | 22 |
3/1/2001 | 23 |
My preferred output should be
Date | No. Of Players |
---|---|
1/1/2001 | 3 |
2/1/2001 | 0 |
3/1/2001 | 2 |
This is my current code, how can I do it within the select:
var convertTable = dataPageTable.AsEnumerable();
Records = new List<List<ContentOutputModel>>(convertTable.Select(dr =>
{
var playerId = dr.GetColumn<long>("PlayerID").ToString();
var dateInt = dr.GetColumn<int>("Date").ToString();
var dateStr = dateInt.Substring(6, 2) + "/" + dateInt.Substring(4, 2) + "/" + dateInt.Substring(0, 4);
var output = new List<ContentOutputModel>(new ContentOutputModel[] {
new ContentOutputModel() { Text = dateStr },
new ContentOutputModel() { Text = playerId },
});
return output;
}));