I have ben trying to figure out how to sort a array by date, all the examples i have found so far, i have had a hard time making any sence of. I got a tab seperated txt file, with the following data.

Date - Meeting - Duration

what i am doing is i am loading some meetings from a text file, and then putting that on top of a picture and saving that as a new picture. I am trying to create a screen, that shows if a meeting room is in use or not.

and my code:

Image img = pictureBox1.Image;
                    Graphics graphic = Graphics.FromImage(img);

                    TextReader sr = new StreamReader(@"C:/Temp/Kalender.txt", Encoding.GetEncoding("iso-8859-1"));
                    string besked = "  EMPTY"; //txt

                    graphic.DrawString(DateTime.Today.ToString("dd/MM/yyyy") + besked, new Font("Arial", 26), new SolidBrush(Color.Black), new PointF(5.0f, 5.0f));
                    string contents = sr.ReadToEnd();
                    string[] myArray = { contents };
                    foreach (string kalenderdata in myArray)
                        // graphic.DrawString( gotya);
                        graphic.DrawString(kalenderdata, new Font("Arial", 18), new SolidBrush(Color.White), new PointF(5.0f, 35.0f));


Recommended Answers

All 2 Replies

Hope this helps:

// sort int array
int[] intArray = new int[5] { 8, 10, 2, 6, 3 };
// write array
foreach (int i in intArray) Console.Write(i + " "); // output: 2 3 6 8 10

// sort string array
string[] stringArray = new string[5] { "X", "B", "Z", "Y", "A" };
// write array
foreach (string str in stringArray) Console.Write(str + " "); // output: A B X Y Z

// ArrayList dates = ...
var sortedDates = dates.OrderByDescending(x => x);
// test it
foreach(DateTime dateTime in sortedDates)

Heres a datetime one for you. Hope you can find a solution from these three examples.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.