Cannot implicilty convert type 'IList'

allelopath
allelopath used Ask the Experts™
on
I get a compile error on this line:
System.Collections.IList instrumentList = new List<Instrument>();

instrumentList = session.CreateCriteria<Financial>("f")
                                       .CreateCriteria("fa.InstrumentList", "il", NHibernate.SqlCommand.JoinType.InnerJoin)
                                        .SetResultTransformer(new NHibernate.Transform.DistinctRootEntityResultTransformer())
                                        .List<Instrument>();

Open in new window

Cannot implicilty convert type 'IList<Instrument>' to Ilist.
What do I need to do?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
why IList just do

List<Instrument> instrumentList = new List<Instrument>();

Author

Commented:
That gives another compile error:
The non-generic Ilist cannot be used with type arguments
Jaime OlivaresSoftware Architect
Top Expert 2008
Commented:
IList has no relationship with IList<>, therefore you cannot convert between them. The unique common interface is IEnumerable
On the other hand, List<> implements IList, so if you can cast a collection to List<> instead of IList<>, then you can assign it to a non-generic IList.
Glanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015
Commented:
Change line 1 to (edited):

System.Collections.Generic.IList<Instrument> instrumentList = new List<Instrument>();

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial