我發佈了一次,似乎無法找到一個簡單的方法來轉換此。我試圖擺脫這種方法的2維數組,ExtractData並使用列表替換它,但沒有運氣。你們能否給我一些我可以脫離的例子或想法?謝謝。如何將2維數組中的代碼轉換爲列表?
private void ExtractData(DateTime dtmDay)
{
// set to selected date in MonthCalendar control
int intChosenDay = dtmDay.Day;
int intFileDay; // day of event from file
int intLineNumbers; // counts lines to skip
m_intNumberOfEvents = 0; // set number of events to 0
// initialize StreamReader to read lines from file
StreamReader objInput =
new StreamReader("calendar.txt");
// read first line before entering loop
string strLine = objInput.ReadLine();
// loop through lines in file
while (objInput.Peek() > -1 &&
m_intNumberOfEvents < 10)
{
intFileDay = Int32.Parse(strLine); // extract day
// if event scheduled for specified day,
// store information
if (intFileDay == intChosenDay)
{
m_strData[ m_intNumberOfEvents, 0 ] = strLine;
m_strData[ m_intNumberOfEvents, 1 ] =
objInput.ReadLine();
m_strData[ m_intNumberOfEvents, 2 ] =
objInput.ReadLine();
m_strData[ m_intNumberOfEvents, 3 ] =
objInput.ReadLine();
m_strData[ m_intNumberOfEvents, 4 ] =
objInput.ReadLine();
m_intNumberOfEvents++;
}
else
{
// skip to next event in file
for (intLineNumbers = 0; intLineNumbers <= 3;
intLineNumbers++)
strLine = objInput.ReadLine();
}
// read day of next event in file
strLine = objInput.ReadLine();
} // end while
} // end method ExtractData
寫功能,一次解決一件事。 – 2013-04-26 21:40:25
'我試圖擺脫這種方法的2維數組,ExtractData並使用列表替換它'你的2-dim數組是怎麼樣的?什麼是你的文件中的數據?你想要提取哪些數據?你的輸出清單應該如何? – I4V 2013-04-26 21:51:27