Hello I have a loop that will need to count the number of occurrences of a date in a datagridview. How can I store that number of occurrences, and increment that number when another of that same date is found? I’m envisioning something like:
for (int k = 0; k < (companyInfo.Rows.Count - 1); k++)
{
for (int j = 0; j< dateArray.Length; j++)
{
if (companyInfo.Rows[k].Cells["StartDate"].Value.ToString().Trim() == dateArray[j])
{
//Find matching index in another array, increment that number
}
}
}
Where companyInfo is a datagridview that I’m looping through each row, dateArray is a static set of dates (could be strings) of length 364, and “another array” would be some sort of separate array that would have a bunch of seemingly random numbers that would represent the occurrences of a date.
Is there a object that already exists that can do this better, or do I have to trace what date corresponds to what values between two arrays? Going to be hard to do things like finding the max/min, average, etc.
Use a
Dictionary<string, int>(in the namespaceSystem.Collections.Generic).