Add data to DataTable I created a class to operate with concrete table and I want to generalize this code to develop more universal class.

Here is one method of this class:

public void FillColumns(DataTable table, OracleDataReader reader)
{
  if (reader != null)
    if (reader.HasRows)
    {
      table.Rows.Clear();
      while (reader.Read()) table.Rows.Add
          (
            reader["ColumnName1"],
            reader["ColumnName2"],
            reader["ColumnName3"],
            reader["ColumnName4"]
          );
    }
}


How can I refactor this concrete method, to make concrete column names as input parameters (even independing of number of columns)?
params (version 1)
You can use the same trick the Rows.Add method uses namely the params keyword

By using the params keyword, you can specify a method parameter that takes a variable number of arguments.

and pass columns names as the last parameters. Then you read the values form the reader with some LINQ and turn it into an array because it's just that, an array (but one that is created dynamically if each value is passed separately). Besides you don't need two ifs, use the and &amp;&amp; operator instead.
public void FillColumns(
    DataTable table, 
    OracleDataReader  reader, 
    params string[] columnNames)
{
    if (reader != null &amp;&amp; reader.HasRows)
    {
        table.Rows.Clear();
        while (reader.Read()) 
        {
            table.Rows.Add(columnNames.Select(name =&gt; reader[name]).ToArray());
        }
    }
}

Example call:
.FillColumns(table, reader, &quot;Column1&quot;, &quot;Column2&quot;);


table.Columns (version 2)
the second approach would be to read the column names from the data table
public void FillColumns(DataTable table, OracleDataReader reader)
{
    if (reader != null &amp;&amp; reader.HasRows)
    {
        table.Rows.Clear();
        while (reader.Read())
        {
            table.Rows.Add(
                table
                .Columns
                .Cast&lt;DataColumn&gt;()
                .Select(column =&gt; reader[column.ColumnName])
                .ToArray());
        }
    }
}


table.Load (version 3)
and the third to just load the datatable from the reader:
public void FillColumns(DataTable table, OracleDataReader reader)
{
    if (reader != null &amp;&amp; reader.HasRows)
    {
        table.Rows.Clear();
        table.Load(reader);        
    }
}