I'm trying to sort dates that are saved in a text document, i have done this using a List. When I try to save the details back into a text document, and inside the document all I see saved is
System.Collections.Generic.List`1[Event_Manager.Form3+MyClass]
This code below is executed with a button, that supposedly sorts the dates, but i can't even see if this code actually sorts the dates, because i keep getting
System.Collections.Generic.List`1[Event_Manager.Form3+MyClass]
saved instead of the original data.
I have tried using .ToString() to prevent this from happening, but it still shows the save output saved into the document.
// Read the file and display it line by line.
StreamReader file = new StreamReader("Events.txt");
List<MyClass> myClassList = new List<MyClass>();
while ((line = file.ReadLine()) != null)
{
string[] split = line.Split(',');
MyClass myclass = new MyClass();
myclass.date = DateTime.Parse(split[2]);
myClassList.Add(myclass);
}
file.Close();
// Sort the list by date
List<MyClass> myClassListSorted = myClassList.OrderByDescending(x => x.date).ToList();
using (StreamWriter sr = new StreamWriter(@"Events.txt"))
{
foreach (var item in myClassList)
{
sr.WriteLine(myClassListSorted.ToString());
}
sr.Close();
}
I should be able to see the actual data that i originally had saved in the text document, but with sorted dates, rather it just has System.Collections.Generic.List`1[Event_Manager.Form3+MyClass]