0

I'm trying to build a class that will hold a row of data from a CSV file along with its header information. Then outside the class I am making a List<> of elements of this class. However I am getting this error which completely worthless, "DynamicCSV does not contain a constructor that takes 1 arguments." Fact is it does in fact contain a constructor with 1 argument.

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(','));
    }
}
4

2 回答 2

6

您需要将构造函数标记为public(或可能internal)。

于 2012-12-04T14:50:02.860 回答
1

制作你的构造public器,否则它不能被“看到”。

于 2012-12-04T14:50:24.330 回答