-5
我應該如何在我的代碼中處理這個錯誤?我試圖改變清單列出,但是會有這個說法是錯誤:不能隱式地將'string'轉換爲'string []'
string time = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss.ff);
下面顯示的是,我做的部分代碼..
List<string[]> dataCollection = new List<string[]>();
List<string> timeCollection = new List<string>();
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
string time = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss.ff");
if (x == unit && count == 3)
{
dataCollection.Add(ReceivedData);
timeCollection.Add(time);
for (int i = 0; i < dataCollection.Count(); i++) //write out all the data lines
{
string[] dataArray = dataCollection[i];
string dataOutput = "";
for (int j = 0; j < dataArray.Length; j++)
{
dataOutput += dataArray[j] +" "; //Link all data to write out
}
for (int k = 4; k > timeCollection.Count(); k--)
{
string[] timeArray = timeCollection[k]; //error for timeCollection[k]
string timeOutput = "";
for (int t = 0; t < timeArray.Length; t++)
{
timeOutput += timeArray[t];
}
}
正如錯誤消息說:'timeCollection [K]'返回一個字符串。另一方面,'dataCollection [k]'返回一個String []。 – user2864740
@ user2864740 right ...所以我應該修改它,以便timeCollection [k]也會返回一個字符串[]。 – Athena
當且僅當這是所需的。然後String []對象必須放入這裏。他們來自哪裏?爲什麼?他們如何使用? (他們甚至認爲是字符串數組?) – user2864740