I'm currently making a program that tracks certain things (basic INT Values and the Date when they were saved).
My goal is to add up the INT values with the same Date.
20.11.2018 00:00:00; 1;1;1;1;1 20.11.2018 00:00:00; 1;1;1;1;1 22.11.2018 00:00:00; 1;1;1;1;1 Should basically look like this
20.11.2018 00:00:00; 2;2;2;2;2 22.11.2018 00:00:00; 1;1;1;1;1 The Saving Data and even the adding the 2 "Lines" together is working perfectly fine.
The problem is that When I add the Lines together, the 2 Lines with the 1 obviously don't get deleted.
This is the Method that Compares the Date and adds the lines together:
public static Dictionary<DateTime, int[]> CompareDateMethod(Dictionary<DateTime, int[]> oDateTimeAndIntDictionary,string[][] ReadData) { Dictionary<DateTime, int[]> oPrintRealData = new Dictionary<DateTime, int[]>(); Dictionary<DateTime, int[]> oAddRealData = new Dictionary<DateTime, int[]>(); for (int i = 0 ; i < ReadData.Length; i++) { DateTime dtDateValue; if (DateTime.TryParse(ReadData[i][0], out dtDateValue)) { int[] iValuesToAdd = ConvertArrayToInt(ReadData[i]); if (dtDateValue.Date == DateTime.Now.Date) { for (int j = 0; j < iValuesToAdd.Length; j++) { oDateTimeAndIntDictionary[dtDateValue.Date][j] += iValuesToAdd[j]; } } else if (dtDateValue.Date != DateTime.Now.Date) { goto Endloop; } } } Endloop: return oDateTimeAndIntDictionary; This is the method that Writes the Data into the .CSV file
Dictionary<DateTime, int[]> oDateTimeAndIntDictionary = new Dictionary<DateTime, int[]>(); string[][] OldData= AddVariables.ReadOldData(); int[] iNewDataArray = new int[] { iVariable1, iVariable2, iVariable3, iVariable4, iVariable5}; oDateTimeAndIntDictionary.Add(DateTime.Now.Date, iNewDataArray); using (System.IO.FileStream fileStream = new System.IO.FileStream(@"C: \Users\---\Csvsave\SaveDatei.csv", System.IO.FileMode.Append, System.IO.FileAccess.Write)) using (System.IO.StreamWriter streamWriter = new System.IO.StreamWriter(fileStream)) { foreach (KeyValuePair<DateTime, int[]> kvp in AddVariables.CompareDateMethod(oDateTimeAndIntDictionary, OldData)) { streamWriter.WriteLine("{0}; {1}", kvp.Key, string.Join(";", kvp.Value)); } } I tried so hard to come up with something but nothing worked (I tried deleting lines from the .csv which seems really hard, I tried reading the file in backwards which didnt work etc.)
If someone can give me some pointers I would really appreciate it.