In the below code block, my DataTable
TelemetryFile is correctly populated. The first MessageBox displays 4.
It also correctly contains a column called FixName. The second MessageBox displays FixName.
However, something is going wrong when I try to create a List<(string FixOrReportName, long CountInTelemetryFile)> of the different FixName values in the table and how often they occur. sortedCountsByName is null and the third MessageBox diplays Hmm.
What am I doing wrong?
public List<(string FixOrReportName, long CountInTelemetryFile)> GetMostPopularOptionsFromTelemetryFile(string typeToReturn, int maxOptionsToReturn)
{
this.TelemetryFile.DefaultView.RowFilter = "FixOrReport = '" + typeToReturn + "'";
MessageBox.Show(this.TelemetryFile.DefaultView.Count.ToString());
MessageBox.Show(this.TelemetryFile.Columns[3].ColumnName);
var sortedCountsByName = (
this.TelemetryFile.AsEnumerable()
.GroupBy(x => x.Field<string>("FixName"))
.Select(x => new Tuple<string, long>(x.Key, x.Count()))
) as List<(string FixOrReportName, long CountInTelemetryFile)>;
if (sortedCountsByName is null)
{
MessageBox.Show("Hmm");
return null;
}
else
{
sortedCountsByName.Sort(
delegate (
(string FixOrReportName, long CountInTelemetryFile) firstPair,
(string FixOrReportName, long CountInTelemetryFile) nextPair)
{
return -1 * firstPair.CountInTelemetryFile.CompareTo(nextPair.CountInTelemetryFile);
}
);
}
return sortedCountsByName.Take(maxOptionsToReturn).ToList();
}