Sorry, I made a Mystake in my question. I would like to convert IList<IEntity> to List<Entity>. Please note that it is a collection of interfaces.
Main Topics
Browse All TopicsIs there a way I can convert IList<object> to List<object>? I tried explicit conversion but I failed.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Sorry Priest04. I reall am sorry. I just found out that actually the object I have is a IList that has IEntity object inside . I get it from a iBatis query and for a reason I don't know, it has to come out this way. I can't declare IList<IEntity> and then execute the query and I will get a conversion error. But suprisingly I cant loop through the list in the snippet.
My problem still however, how do I convert that IList in a List<Entity>?
I am not familiar with the internal mechanism of the ToArray method, but could be that the code is literating twice, so the performance can drop. Test it to see which one runs faster, and use the faster onr, not the "better looking" one.
btw
>> This is actually what I am using but I wanted another approach that doesn't require iterations.
All methods reqire iterations, its just weather you will do it in the code, or they will provide a method that does an iteration.
And there is no other way to achieve what you want.
Business Accounts
Answer for Membership
by: Priest04Posted on 2008-10-10 at 02:37:11ID: 22685380
ILIst<T> coll1 = GetData();
List<T> coll2 = (List<T>)coll1;
or you can do it in single line, when getting data;
List<T> coll2 = GetData() as List<T>; // where GetData returns IList<T>
Goran