title: How to convert boolean to int in itemarray using datatable?
body: <p>How I convert <code>boolean</code> value to int (1 for <code>True</code> and 2 for <code>false</code>) inside <code>ItemArray</code>. Below is function for converting <code>DataTable</code> to csv.</p>
  
  <pre><code>public  string ToCSV(DataTable tbl, Boolean ColumnHeader)
      {
          string FinalResult = string.Empty;
          StringBuilder strb = new StringBuilder();
  
          if (ColumnHeader == true)
          {
              //column headers
              strb.AppendLine(string.Join(",", tbl.Columns.Cast&lt;DataColumn&gt;()
                  .Select(s =&gt; "\"" + s.ColumnName + "\"")));
          }
          //rows
          tbl.AsEnumerable().Select(s =&gt; strb.AppendLine(
             string.Join(",", s.ItemArray.Select(
                 i =&gt; "\"" + i.ToString() + "\"")))).ToList();
          FinalResult = strb.ToString();
          strb= null;
          return FinalResult; 
          //return strb.ToString();
      }
  </code></pre>