This is a migrated thread and some comments may be shown as answers.

Problem using IList

1 Answer 92 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Dennis Gundersen
Top achievements
Rank 1
Dennis Gundersen asked on 26 Feb 2010, 09:06 PM
Hi

I'm trying to implement List<> in my project, but OA says I must use IList instead. I tested using a Person and Address class. The Person class has an IList of Address objects.

I then came across this situation:
//Doesn't work  
private IList<Address> _addresses = new IList<Address>();  
// Does work  
private IList<Address> _addresses = new List<Address>(); 
Does using the last version come with any problems down the road?

Also, is it a good idea to include a Person object in class Address so that I can go from Address.Person.whatever in addition to Person.Addresses.whatever?

Re
Dennis

1 Answer, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 28 Feb 2010, 06:40 PM
Hi Dennis Gundersen,

IList<> is an interface and thereby you cannot instantiate it. It just declares what properties / methods should be defined in the classes that implement it. What you should do instead, is to create an instance of a class that implements that interface. In your example, the second line is what you need.
And  yes, in most cases it is useful to have an inverse reference and not only a collection at one of the relation ends. To make sure that your Person.Addresses and Address.Person properties are synchronized (represent the same relation), you should open the Forward mapping wizard, select the addresses field in the treeview and choose the person field in the Inverse Field combobox. Hope that helps.

Best wishes,
Alexander
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
General Discussions
Asked by
Dennis Gundersen
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Share this question
or