Posted on: 11/6/2014 10:10:40 PM | Views : 703

I have a datatable I receive and use in code for a while but now the requirement is for it to be an IList when I pass it on.  How do I convert a datatable to an Ilist without going back to the database query, which I don't have access to?  Is there a way without looping through the datatable.rows and manually adding each field to the IList object type instance and then adding the instance to the IList?

For example; if I have an IList of type Foo and Foo has Yoo and Hoo as properties, I can manually loop through the datarows and set Foo property Yoo to the value of datarow("Yoo") and then Foo property Hoo to the value of datarow("Hoo").  Then I can do an Add.Item on the Ilist of the instance of Foo.  I will eventually end up with an IList full of Foo instances.  I'm hoping for something like a type cast or maybe how a table can shift between a view and back to a table so I would only need a few lines of code instea ...

Go to the complete details ...