![](/img/trans.png)
[英]'ListViewItem' does not contain a constructor that takes 1 argument
[英]Does not contain a constructor that takes 1 argument even though there is a constructor that takes 1 argument
我正在嘗試建立一個類,該類將保存CSV文件中的一行數據及其標題信息。 然后在類之外,我對該類的元素進行List <>。 但是,我得到的錯誤完全沒有價值,“ DynamicCSV不包含帶有1個參數的構造函數。” 實際上,它實際上包含一個帶有1個參數的構造函數。
class DynamicCSV : DynamicObject
{
public List<string> columnHeaders;
public List<string> rowData;
/* Constructor with 1 argument */
DynamicCSV(List<string> headers)
{
columnHeaders = new List<string>();
dynamic rowData = new List<string>();
columnHeaders = headers;
}
}
/* code that calls the constructor */
while (!streamReader.EndOfStream)
{
List<string> headers = new List<string>();
List<string> dataRow = new List<string>();
List<DynamicCSV> dataRows = new List<DynamicCSV>();
if (true == isHeaderRow)
{
currentRow = streamReader.ReadLine();
headers.AddRange(currentRow.Split(','));
dataRows.Add(new DynamicCSV(headers)); // here is the error
isHeaderRow = false;
}
else
{
currentRow = streamReader.ReadLine();
dataRow.AddRange(currentRow.Split(','));
}
}
您需要將構造函數標記為public
(或可能是internal
)。
將您的施工方public
,否則將無法“看到”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.