C# Console App

Right, I have split the data from the text file up into individual elements using the Split.Line and splitting it by commas.

Now I can do Person.Surname = parts[0] - meaning the first elements are the surnames, second names are the second etc.

Now when I WriteLine Person.FirstName, Person.Surname it displays all of the records as opposed to just one record. I need to set up some kind of index I think, i.e. if x is pressed display first record, if y is pressed display the next as opposed to it displaying all of the records.

Any idea how I can set up a counter, index for each individual record so I can display individual records as opposed to all the data?

Cheers
Tom.
 
What you need to do is load up each separate class into a separate element of the array/list/container. This is VERY important (I'm not sure if you have done this already).

you will have a counter. [int counter = 0;]

Assume class name = Person.
Assume list/array name = person.

your pseudo code will read something like:

if keyPress == "y"
{
counter++
WriteLine person[counter].FirstName, person[counter].Surname
}

if keyPress == "x"
{
WriteLine person[0].FirstName, person[0].Surname, ie. the first element of the array
}


Is this for a homework assignment?
 
Code:
        static void Main()
        {
            using (StreamReader reader = new StreamReader("data.txt"))
            {
                string line;
                int count = 0;
                while ((line = reader.ReadLine()) != null)
                {
                    //int lineCount = File.ReadAllLines("data.txt").Length;
                    //Console.WriteLine(lineCount);
                    count++;
                    string[] parts = line.Split(',');
                    Student Person;
                    Person.detail = parts[0];
                    Person.test = parts[1];
                    Person.detail = parts[2];
                    Person.test = DateTime.Parse(parts[3]);
                    Person.detail = Char.Parse(parts[4]);
                    Console.WriteLine(Person.detail + "\t" + Person.test + "\t" + Person.detail + "\t" + String.Format("{0:MM/dd/yyyy}", Person.test) + "\t" + Person.detail);
                    Console.WriteLine(parts);

No it isn't a homework question - just a task that I am doing.

So what I am trying to do now is to show the individual records as opposed to all of them at the same time. I think I need to use the counter somehow, maybe to incorporate it into some kind of array. Keep trying all sorts and just can't get it to work.
 
Back
Top Bottom