我試圖將special.Day
的值傳遞給intFileDay
,具體取決於events[]
。例如,如果我想從事件[3]中獲得特殊的日期值......我將如何引用它,以便我可以說intFileDay = event[3].special.Day
??我將如何引用列表中的數組的1行,以便我可以傳遞該值?
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;
}
您使用的是列表,而不是一個數組。你可以調用'intFileDay = events [3] .Day'。 – 2013-04-26 09:00:45