Click here to Skip to main content
15,884,962 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all. I'm going to say first off that this is not a homework project.
I have a little experience writing small programs for my own personal use, although it's been a while. I have a problem that I hope some of you can shed some light on.

I'm writing a small program to parse some csv files for handicapping horse races. There are three files with a ton of information. I'm only concerned with a small amount of that data. I am attempting to arrange the data and then write that data back to a csv file that can be opened in excel.
So what I have is a Race class:
public class Race
       {
           public string RaceNumber { get; set; }
           public string RaceDate { get; set; }
           public string Track { get; set; }
           public string Distance { get; set; }
           public string Surface { get; set; }
           public List<Horse> Horses = new List<Horse>;
       }


and the horse class:
public class Horse
       {
           public string HorseName { get; set; }
           public string raceNumber { get; set; }
           public string HorseNumber { get; set; }
           public string[] PP = new string[10];

       }


I also have a list called raceList that contains all of the race classes.
I can loop through this and see that the data is correct. However, when I attempt to check the list of Horses inside the race class, I encounter a problem. I'm sure it has something to do with the way that I've set this up.
So I have a list<class> Race that contains a list<classs> Horses. I tried to loop through them in this manner:
foreach (Race race in raceList)
                  {
                      Debug.WriteLine(race.Track);
                      Debug.WriteLine(race.RaceDate);
                      Debug.WriteLine(race.RaceNumber);
                      foreach (Horse horse in Horses)
                      {
                          Debug.WriteLine(horse.HorseNumber);
                          Debug.WriteLine(horse.HorseName);
                      }


                  }


Right now I am currently using the debug writeline to check the data to make sure its in the proper place, but I'm getting "the name Horses does not exist in the current context.It properly loops through the raceList. I'm stumped. I tried googling (It's been a while since I've done this so I've been googling a bunch), but I haven't found anything.
If anyone has any ideas, I'd much appreciate it.
Thanks for taking the time to read.

What I have tried:

I've been googling this to no avail. I simply have no idea.
Posted
Updated 23-Feb-20 2:26am

Did you tried something like:
C#
foreach (Race race in raceList)
{
    Debug.WriteLine(race.Track);
    Debug.WriteLine(race.RaceDate);
    Debug.WriteLine(race.RaceNumber);
    foreach (Horse horse in race.Horses)
    {
        Debug.WriteLine(horse.HorseNumber);
        Debug.WriteLine(horse.HorseName);
    }


}
 
Share this answer
 
v2
Comments
phil.o 22-Feb-20 16:02pm    
5'd
You should correct the casing of the race variable, though :)
Patrice T 22-Feb-20 17:48pm    
Thank you.
Corrected :)
Maciej Los 23-Feb-20 7:47am    
5ed!
Patrice T 23-Feb-20 9:32am    
Thank you
That did the trick.Thanks a bunch.
Always seems to be something easy that I overlook. I really need to go back through with some good tutorials.
I really appreciate the quick response.
Hope you all have a great weekend.
 
Share this answer
 
Comments
Patrice T 23-Feb-20 9:42am    
Advice: Do not use a solution to discuss with author of a solution, instead use the "Have a Question or Comment?" button on bottom of solution. Advantage, author is notified.
When a solution was useful, you can also accept it, this tells everyone that the problem is solved.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900