Sometimes we need to show some random rows from a datatable in c#.For achieving this we can use Random Class which is present in base class library
and create a random number .Now we use this random number to order datatable.Here is the code snippet for the same.
Further we can select limited number of rows by slightly modifying the above syntax.var rand = new Random(); var employees = employee.AsEnumerable().OrderBy(r => rand.Next());
Take method will select number of rows specified as parametervar rand = new Random(); var employees = employee.AsEnumerable().OrderBy(r => rand.Next()).Take(10);
No comments :
Post a Comment