Friday, October 23, 2009

Converting IList to List

I was working and had an error trying to cast from an IList type to a generic List type object.

After trolling the intertubes, I found the following, tried it out and what do we know; it works!

Step 1
Declare an empty generic list of whatever type you want.
eg: List object1 = new List();

Step 2
Use the AddRange method from the generic list class.
eg: object1.AddRange(IList_object);

No comments:

Post a Comment