Collections set accessors

Discussion in 'Microsoft Dot NET' started by Mikeyranks, Aug 2, 2007.

  1. Mikeyranks

    Mikeyranks Guest

    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 = myImageCollection;


    Any elements in myImageCollection 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
     
    Mikeyranks, Aug 2, 2007
    #1
    1. Advertisements

  2. Mikeyranks

    Mr. Arnold Guest

    "Mikeyranks" <> wrote in message
    news:...
    > 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 = myImageCollection;


    That imageList.Images is derived from System.Windows.Forms Namespace.

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


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

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

    Names1 = Names.GetNames() // with GetNames returning System.Collection.
     
    Mr. Arnold, Aug 2, 2007
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. Steven Quail

    XML documentation for accessors.

    Steven Quail, Oct 2, 2003, in forum: Microsoft Dot NET
    Replies:
    2
    Views:
    196
    Steven Quail
    Oct 3, 2003
  2. Rick Clift

    Serializable Objects in Collections over a Web Service

    Rick Clift, Oct 8, 2003, in forum: Microsoft Dot NET
    Replies:
    0
    Views:
    255
    Rick Clift
    Oct 8, 2003
  3. TP-Software
    Replies:
    0
    Views:
    244
    TP-Software
    Oct 12, 2003
  4. John

    protected variables or protected accessors?

    John, Jan 7, 2004, in forum: Microsoft Dot NET
    Replies:
    1
    Views:
    402
    Jon Skeet [C# MVP]
    Jan 7, 2004
  5. Helium
    Replies:
    1
    Views:
    871
    Mattias Sjögren
    Apr 2, 2005
  6. cody
    Replies:
    2
    Views:
    256
    Mattias Sjögren
    Jun 4, 2005
  7. Harlan Messinger

    Events with accessors

    Harlan Messinger, Nov 29, 2007, in forum: Microsoft Dot NET
    Replies:
    7
    Views:
    306
    Jon Skeet [C# MVP]
    Nov 30, 2007
  8. DR
    Replies:
    1
    Views:
    382
    Peter Ritchie [C# MVP]
    Apr 9, 2008
Loading...