Forums - C# Corner

Forum guidelines
Pinpoint Solutions

Pinpoint Solutions

  • 1.5k
  • 11
  • 2.9k

How to dynamically cast a Table to a List

Dec 12 2012 3:15 AM

I have the following piece of code:

ITable tResults = myDataContext.GetTable(myObjectType); Type myListType = typeof(List<>).MakeGenericType(myObjectType);

So, I get the table data from object type which gives me a Linq.Table object (line 1).

Now, in line 2 I dynamically create a List<type> where Type comes from the myObjectType Type variable.

my Question: How do I convert/cast my Linq.Table to a strongly typed List List<myType> ?

Answers (1)