arraylist.readonly equivalent.

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

    #1

    arraylist.readonly equivalent.

    hi all,


    Iam trying to create my own collection, on the lines of Arratlist, and
    iam trying to implement something like ArrayList.Reado nly ,return a
    readonly version of the same collection ...

    any thoughts ?

    TIA


  • Rob Windsor [MVP]

    #2
    Re: arraylist.reado nly equivalent.

    Create a class that inherits from System.Collecti ons.CollectionB ase,
    implement the standard methods (i.e. Add, Insert, Remove, Item, etc), add a
    boolean IsReadOnly property, then in any method or property that would
    modify the internal List throw an exception if the IsReadOnly property is
    true.

    --
    Rob Windsor [MVP-VB]
    G6 Consulting
    Toronto, Canada



    "Ashish" <asharma@thisis junk.com> wrote in message
    news:%239VvVjO2 FHA.1576@TK2MSF TNGP15.phx.gbl. ..[color=blue]
    > hi all,
    >
    >
    > Iam trying to create my own collection, on the lines of Arratlist, and iam
    > trying to implement something like ArrayList.Reado nly ,return a readonly
    > version of the same collection ...
    >
    > any thoughts ?
    >
    > TIA
    >
    >[/color]


    Comment

    • Ashish

      #3
      Re: arraylist.reado nly equivalent.

      Thanks Rob,

      I was also wondering as to why am i not able to implement a function
      named ReadOnly(list Ilist) , that returns IList, but Arraylist has that
      implementation ? ( it complains of ReadOnly being a reserved word...)

      regards


      Rob Windsor [MVP] wrote:[color=blue]
      > Create a class that inherits from System.Collecti ons.CollectionB ase,
      > implement the standard methods (i.e. Add, Insert, Remove, Item, etc), add a
      > boolean IsReadOnly property, then in any method or property that would
      > modify the internal List throw an exception if the IsReadOnly property is
      > true.
      >[/color]

      Comment

      • Rob Windsor [MVP]

        #4
        Re: arraylist.reado nly equivalent.

        If you want to use a reserved word for the name of a member just surround it
        with square brackets. For example:

        Public Sub [ReadOnly](ByVal list As IList)

        --
        Rob Windsor [MVP-VB]
        G6 Consulting
        Toronto, Canada


        "Ashish" <asharma@thisis junk.com> wrote in message
        news:uVJz%23YY2 FHA.2268@TK2MSF TNGP15.phx.gbl. ..[color=blue]
        > Thanks Rob,
        >
        > I was also wondering as to why am i not able to implement a function named
        > ReadOnly(list Ilist) , that returns IList, but Arraylist has that
        > implementation ? ( it complains of ReadOnly being a reserved word...)
        >
        > regards
        >
        >
        > Rob Windsor [MVP] wrote:[color=green]
        >> Create a class that inherits from System.Collecti ons.CollectionB ase,
        >> implement the standard methods (i.e. Add, Insert, Remove, Item, etc), add
        >> a boolean IsReadOnly property, then in any method or property that would
        >> modify the internal List throw an exception if the IsReadOnly property is
        >> true.
        >>[/color][/color]


        Comment

        Working...