-1

I am trying to pass a value from special.Day to intFileDay depending on the events[]. For example, if I want to get special.Day value from event[3]......how would I reference that so that I can say intFileDay = event[3].special.Day ??

public List<Event> ExtractData(DateTime dtmDay)
  {
     int intChosenDay = dtmDay.Day;
     int intFileDay;

     StreamReader textIn =
    new StreamReader(
    new FileStream(path, FileMode.OpenOrCreate, FileAccess.Read));

     //create the list
     List<Event> events = new List<Event>();

     string[] lines = File.ReadAllLines(path);


     for (int index = 4; index < lines.Length; index += 5)
     {
        Event special = new Event();
        special.Day = Convert.ToInt32(lines[index - 4]);
        special.Time = (lines[index - 3]);
        special.Price = Convert.ToDouble(lines[index - 2]);
        special.StrEvent = lines[index - 1];
        special.Description = lines[index];
        events.Add(special);
     }



     textIn.Close();

     return events;

  }
4

1 回答 1

0

因为events[]是一个Event类型列表,每个元素都是一个Event,所以你可以这样做:

int fileDay = events[index].Day;
于 2013-04-26T09:00:18.997 回答