我試圖從函式回傳一個命名元組并得到一個錯誤。這是一個示例代碼。
public List<(int row, string message)> IsAnyTagNull()
{
List<Tuple<int, string>> rows = new List<Tuple<int, string>>();
for (int row = rowindex; row < (range.RowCount (rowindex - 1)); row )
{
rows.Add(new Tuple<int, string>(row, "Cell Tag is null of row " row));
}
return rows
}
以上代碼回傳錯誤
無法將型別 'System.Collections.Generic.List<System.Tuple<int, string>>' 隱式轉換為 'System.Collections.Generic.List<(int row, string message)>'
uj5u.com熱心網友回復:
因為List<Tuple<int, string>>不同于List<(int row, string message)>
您可以嘗試創建一個List<(int row, string message)>型別而不是List<Tuple<int, string>>
public List<(int row, string message)> IsAnyTagNull()
{
List<(int row, string message)> rows = new List<(int row, string message)>();
rows.Add((1, "Cell Tag is null of row "));
return rows;
}
uj5u.com熱心網友回復:
您應該像這樣定義您的串列:var rows = new List<(int row, string message)>();
型別Tuple<int, string>被解釋為(int Item1, string Item2)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/462709.html
上一篇:如果檔案已經存在,如何覆寫它?
下一篇:C#linq回傳串列的每第n行
