Problem using IList

Thread is closed for posting
2 posts, 0 answers
  1. Dennis Gundersen
    Dennis Gundersen avatar
    23 posts
    Member since:
    Dec 2009

    Posted 26 Feb 2010 Link to this post

    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
  2. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 28 Feb 2010 Link to this post

    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.
Back to Top