Cannot implicilty convert type 'IList'

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?
LVL 1
allelopathAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
käµfm³d 👽Connect With a Mentor Commented:
Change line 1 to (edited):

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

Open in new window

0
 
p_davisCommented:
why IList just do

List<Instrument> instrumentList = new List<Instrument>();
0
 
allelopathAuthor Commented:
That gives another compile error:
The non-generic Ilist cannot be used with type arguments
0
 
Jaime OlivaresConnect With a Mentor Software ArchitectCommented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.