Jak mogę to zrobić żeby przy kolejnym dodaniu do listy main ten wcześniejszy mi się nie nadpisywał ?
List<ListToDo> main = new List<ListToDo>();
string filePatch = @"C:\Users\PK\source\repos\ConsoleApp5\ConsoleApp5\File.txt";
List<string> lines = File.ReadAllLines(filePatch).ToList();
List<string> buffList = new List<string>();
ListToDo buff = new ListToDo();
for (int i = 0; i < lines.Count; i++)
{
if (i % 4 == 0)
{
buff.Date = lines[i];
}
if (i % 4 == 1)
{
buff.Note = lines[i];
}
if (i % 4 == 2)
{
buff.Status = Convert.ToBoolean(lines[i]);
}
if (i % 4 == 3)
{
buff.Category = lines[i];
main.Add(buff);
}
}
Przykład pliku txt:
Dziś
Jakaś notatka
true
IT
jutro
Jakaś inna notatka
false
sport
bo teraz mam w wyniku zapisania 2 razy to drugie:
jutro
Jakaś inna notatka
false
sport
jutro
Jakaś inna notatka
false
sport