我如何引用list中数组的一行,以便传递值
本文关键字:一行 数组 何引用 引用 list | 更新日期: 2023-09-27 18:11:10
我正试图根据events[]
传递从special.Day
到intFileDay
的值。比如,如果我想变得特别。事件[3]......的日值我怎么引用它,这样我才能说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;
}
由于events[]
是Event
类型的列表,因此每个元素都将是Event
,因此您可以这样做:
int fileDay = events[index].Day;