Microsoft.Xunit.Performance.Api.Table.DataTable.AddColumn C# (CSharp) Method

AddColumn() public method

public AddColumn ( string name ) : ColumnName
name string
return ColumnName
        public ColumnName AddColumn(string name)
        {
            return _ColumnNames.Add(name);
        }

Usage Example

Exemplo n.º 1
0
        public static DataTable ReadFromCSV(string fullFilePath)
        {
            DataTable table = new DataTable();

            using (CSVReader reader = new CSVReader(fullFilePath))
            {
                // Create columns.
                ColumnName[] columns = new ColumnName[reader.TitlePositions.Count];
                int columnIndex = 0;

                foreach (KeyValuePair<string, int> titleInfo in reader.TitlePositions.OrderBy(p => p.Value))
                {
                    columns[columnIndex++] = table.AddColumn(titleInfo.Key);
                }

                // Iterate through each row in the CSV file and add the data to the table.
                for (int rowIndex = 0; rowIndex < reader.Length(); rowIndex++)
                {
                    // Create a new row.
                    Row row = table.AppendRow();
                    for(columnIndex = 0; columnIndex < columns.Length; columnIndex++)
                    {
                        ColumnName columnName = columns[columnIndex];
                        row[columnName] = reader.GetValue(rowIndex, columnName.Name);
                    }
                }
            }

            return table;
        }
All Usage Examples Of Microsoft.Xunit.Performance.Api.Table.DataTable::AddColumn