For-Loop approach:
int columnIndex = 0; //single-column DataTable
string[] userArr = new string[dt.Rows.Count];
for( int i = 0; i < dt.Rows.Count; i++)
{
userArr[i] = dt.Rows[i][columnIndex].ToString();
}
LINQ approach 1:
int columnIndex = 0; // single-column DataTable
var userArr = dt.Rows.Cast
.Select(row => row[columnIndex].ToString())
.ToArray();
LINQ approach 2:
int columnIndex = 0; // single-column DataTable
List
foreach( DataRow row in dt.Rows )
{
userList.Add( row[columnIndex].ToString() );
}
No comments:
Post a Comment