I have a list and I am getting each item in the list in a foreach loop.
private void saveButton_Click(object sender, EventArgs e)
{
if (saveFile1.ShowDialog() == DialogResult.OK)
{
StreamWriter sw = new StreamWriter(saveFile1.FileName);
int i = 1;
Dictionary<string, int> dictionary = new Dictionary<string, int>();
foreach (var line in theFinalList)
{
//compareList.Add(line.PartNumber[]);
if (!line.Name.Contains("FID") || !line.PartNumber.Contains("FIDUCIAL") ||
!line.PartNumber.Contains("EXCLUDES") || !line.PartNumber.Contains("excludes"))
{
//This doesn't work obviously.. :/
sw.WriteLine("( {0} 0 1 1 0 0 0 0 \"{1}\" \"{2}\" \"\" {3} 0 0 0 0 0 )",
i, line.PartDescription, line.PartNumber, partNumberOccurrences);
}
i++;
}
}
And I am having trouble using a dictionary to store each part of the line in a dictionary and to increment the the itemCounter whenever it is found as duplicate. I am trying to do something like this, but I cannot figure out the logic for it.
And I would like to only output the partNumber 1 time and also the amount of times it occurred as well as a corresponding value on the same line as the partNumber.
The output would look like this:
( 1 0 1 1 0 0 0 0 "2125R_1.0" "136380" "" 18 0 0 0 0 0 )
( 2 0 1 1 0 0 0 0 "2125R_1.0" "128587" "" 41 0 0 0 0 0 )
( 3 0 1 1 0 0 0 0 "2125R_1.0" "138409" "" 11 0 0 0 0 0 )
( 4 0 1 1 0 0 0 0 "2125R_1.0" "110984" "" 8 0 0 0 0 0 )
( 5 0 1 1 0 0 0 0 "3216R_1.3" "114441" "" 6 0 0 0 0 0 )
( 6 0 1 1 0 0 0 0 "3216C_1.3" "2006722" "" 16 0 0 0 0 0 )
( 7 0 1 1 0 0 0 0 "3216C_1.3" "135732" "" 6 0 0 0 0 0 )
Can anyone help me with creating a dictionary to do this?
1 Answer