void Datatablelambdatest ()
{
DataTable dt = new DataTable ();
Dt. Columns.Add ("userid");
Dt. Columns.Add ("username");
Dt. Columns.Add ("class");
DataRow dr = dt. NewRow ();
dr["userid"] = "0";
dr["username"] = "Zhang San";
Dr["class"] = "class One";
Dt. Rows.Add (DR);
DataRow DR1 = dt. NewRow ();
Dr1[0] = "1";
DR1[1] = "John Doe";
DR1[2] = "Class Two";
Dt. Rows.Add (DR1);
DataRow DR2 = dt. NewRow ();
Dr2[0] = "3";
Dr2[1] = "Harry";
DR2[2] = "one shift";
Dt. Rows.Add (DR2);
Dt. AcceptChanges ();
var result =dt. AsEnumerable (). Where<datarow> (A = a["class"]. ToString () = = "one Shift");
int Row=result. Count ();
Console.WriteLine ("One class has" +row+ "students");
foreach (DataRow drn in result)
{
Console.WriteLine ("userid:" + drn["userid"]. ToString () + ", Username:" + drn["username"]. ToString () + ", class:" + Drn["class"]. ToString ());
}
}
The result of the call output is:
DataTable using lambda expressions