I have stored the following information in text file. I am using the file stream and stream reader object to read it. I got an array method:
string[] MyArray = allText.Split(new string[]{" ",Environment.NewLine},
StringSplitOptions.RemoveEmptyEntries);
This is to store the entire content of a text file by splitting in terms of words.
How do i do the same thing and make the following data get stored in a multidimensional arraylist. By sorting it.
Princeton 12/12/2013 04:13PM
Leon 10/11/2013 05:13PM
Shawn 09/09/2013 04:00PM
Sandy 07/09/2012 09:00AM
Grumpy 18/09/2013 10:00AM
Visualize it like in tables. All this data is stored in a multidimensional array list. Names have to be sorted and stored, date has to be sorted and stored and time has to be sorted and stored. Only the particular format in each given case is accepted.
This is what i tried but it keeps generating an error stating that the get and set methods have not been marked as extern or abstract and therefore must have a body.
using System;
using System.Collections;
using System.IO;
using System.Text;
class Planner
{ public string firstName { get; set;}
public string lastName { get; set; }
public DateTime dateTime { get; set; }
}
class exe
{
public static void Main(string[] args)
{
List<Planner> t = new List<Planner>();
StreamReader sr = new StreamReader("@cScheduler.txt"))
{
string line = string.Empty;
while ((line = sr.ReadLine()) != null)
{
string[] lines = line.Split(' ').ToArray();
//add to your list
t.Add(new Test() { firstName = lines[0], lastName = lines[1], dateTime = DateTime.ParseExact("MM/dd/yyyy hh:mm:ss tt",
lines[2] + lines[3],
CultureInfo.InvariantCulture) });
}
} //Your Ordered list now t = t.OrderBy(x => x.dateTime).ToList<Planner>();
} }
class LineObject { string Name {get;set;} DateTime DateValue {get;set;} }, read all the lines into that structure and have aList<LineObject>to hold them. Then you canOrderBy(x => x.Name)orx => x.DateValue.DateorOrderBy(x => x.DateValue.Hour).ThenBy(x => x.DateValue.Minute).