Collections set accessors

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mikeyranks

    #1

    Collections set accessors

    Using the .NET framework and some other third party API's I've
    noticed
    that objects with a collection property generally don't have a set
    accessor? That is to say I have not yet managed to find one yet.

    After searching around I've not managed to find a reason why other
    than that it forces you to use the the provided .Add(), .Remove(),
    RemoveAt() methods of the collection.


    Why cant I do something like:


    this.imageList1 .Images = myImageCollecti on;


    Any elements in myImageCollecti on would have had to have used these
    methods anyway so I can't see why I have to enumerate and add
    individually.


    I cannot seem to find any information as to why this is? Is there an
    unspoken rule or design pattern that discourages setting all the
    collection elements in one go? Is this the same across other
    languages/platforms?


    Thanks

  • Mr. Arnold

    #2
    Re: Collections set accessors


    "Mikeyranks " <michael.ground s@googlemail.co mwrote in message
    news:1186075645 .395284.72000@i 38g2000prf.goog legroups.com...
    Using the .NET framework and some other third party API's I've
    noticed
    that objects with a collection property generally don't have a set
    accessor? That is to say I have not yet managed to find one yet.
    >
    After searching around I've not managed to find a reason why other
    than that it forces you to use the the provided .Add(), .Remove(),
    RemoveAt() methods of the collection.
    >
    >
    Why cant I do something like:
    >
    >
    this.imageList1 .Images = myImageCollecti on;
    That imageList.Image s is derived from System.Windows. Forms Namespace.

    A collection is derrived form the System.Collecti on Namespace, and I am
    pretthy sure you can't get away with that up above.


    If Names1 and Names2 are derived from System.Collecti on you should be ables
    to do Name1 = Name2

    Or if a method was returning a System.Collecti on then you can do this.

    Names1 = Names.GetNames( ) // with GetNames returning System.Collecti on.


    Comment

    Working...