我如何引用列表中数组的1行,以便我可以传递该值?

时间:2013-04-26 08:56:51

标签: c#

我正在尝试将值从special.Day传递到intFileDay,具体取决于events[]。例如,如果我想从event [3]得到特殊的.Day值......我将如何引用它以便我可以说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;

  }

1 个答案:

答案 0 :(得分:0)

由于events[]Event类型的列表,因此每个元素都是Event,因此您可以这样做:

int fileDay = events[index].Day;