Let\'s say I have a DataTable with ~50 rows (GetDataTable() on a list in SharePoint). I want to keep 10 random rows and forget about the rest. How can I achieve this?
The DataTable contain a property Rows that is a DataRowCollection. You can access each of those rows by using index.
Rows
DataRowCollection
So you can get random number with Random and get the data from the myTable.Rows[myRandomIndex].
Random
myTable.Rows[myRandomIndex]
Random random = new Random(); int randomNumber = random.Next(0, 50);