Convert generic List/Enumerable to DataTable?

I have few methods that returns different Generic Lists.

Exists in .net any class static method or whatever to convert any list into a datatable? The only thing that i can imagine is use Reflection to do this.

IF i have this:

List<Whatever> whatever = new List<Whatever>();

(This next code doesn’t work of course, but i would like to have the possibility of:

DataTable dt = (DataTable) whatever;

28 Answers
28

Leave a Comment