C#: retrieve the first n records from a DataTable

c#, dataset

Solution

If it implements `IEnumerable<T>`:

var first100 = table.Take(100);

If the type in question only implements IEnumerable, you can use the Cast extention method:

var first100 = table.Cast<Foo>().Take(100);

Problem

I have a `DataTable` that contains 2000 records. How would you retrieve the first 100 records in the `DataTable`?

Original source