C# 不包含接受1个参数的构造函数,即使存在接受1个参数的构造函数
我正在尝试构建一个类,该类将保存CSV文件中的一行数据及其头信息。然后在课堂之外,我列出了这个类的元素。然而,我得到了这个完全没有价值的错误,DynamicCSV不包含接受1个参数的构造函数。事实上,它确实包含一个带1个参数的构造函数C# 不包含接受1个参数的构造函数,即使存在接受1个参数的构造函数,c#,C#,我正在尝试构建一个类,该类将保存CSV文件中的一行数据及其头信息。然后在课堂之外,我列出了这个类的元素。然而,我得到了这个完全没有价值的错误,DynamicCSV不包含接受1个参数的构造函数。事实上,它确实包含一个带1个参数的构造函数 class DynamicCSV : DynamicObject { public List<string> columnHeaders; public List<string> rowData; /* Const
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,否则它将无法被“看到”。哇,谢谢!那太棒了。得到答案只需<60秒。我是个白痴,但是谢谢。不用担心,我们都有这样的时刻。