title: DataTable Extension methods C#
body: <p>I have a method to perform operation in Datatable. </p>
  
  <pre><code>public DataTable SetColumnsOrder(DataTable table, String[] columnNames)
      {
          int columnIndex = 0;
          foreach (var columnName in columnNames)
          {
              if (table.Columns.Contains(columnName))
              {
                  table.Columns[columnName].SetOrdinal(columnIndex);
                  columnIndex++;
              }
          } return table;
      }
  </code></pre>
  
  <p>To access this method I need to do like this</p>
  
  <pre><code>dt = SetColumnsOrder(dt,colNames);
  </code></pre>
  
  <p>Instead of doing like this, how to create a function to call it like below in c#</p>
  
  <pre><code>dt.SetColumnOrder(colNames);
  </code></pre>
  
  <p>where the function should take dt as input to perform operations and store back in same dt.</p>