ArrayList and System.Array ?

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

    ArrayList and System.Array ?

    Hi,

    How to create an ArrayList from a System.Array or inserting the System.Array
    into the ArrayList ?

    Thanks
    Ole


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: ArrayList and System.Array ?

    Ole,

    You can pass the array into the constructor of the ArrayList. It takes
    an ICollection, which all arrays implement.

    If you have a need to add an existing array to an array list, then you
    can call the AddRange method, and pass the array through that.

    Hope this helps.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "ORC" <orc@sol.dk> wrote in message
    news:enHmJiV2EH A.3756@TK2MSFTN GP10.phx.gbl...[color=blue]
    > Hi,
    >
    > How to create an ArrayList from a System.Array or inserting the
    > System.Array
    > into the ArrayList ?
    >
    > Thanks
    > Ole
    >
    >[/color]


    Comment

    • Peter Rilling

      #3
      Re: ArrayList and System.Array ?

      Array implements IList and ICollection. Take a look at the constructors for
      ArrayList.

      Or you could use AddRange with a blank list.

      "ORC" <orc@sol.dk> wrote in message
      news:enHmJiV2EH A.3756@TK2MSFTN GP10.phx.gbl...[color=blue]
      > Hi,
      >
      > How to create an ArrayList from a System.Array or inserting the[/color]
      System.Array[color=blue]
      > into the ArrayList ?
      >
      > Thanks
      > Ole
      >
      >[/color]


      Comment

      • Jon Skeet [C# MVP]

        #4
        Re: ArrayList and System.Array ?

        ORC <orc@sol.dk> wrote:[color=blue]
        > How to create an ArrayList from a System.Array[/color]

        As others have said, the constructor which takes an ICollection.
        [color=blue]
        > or inserting the System.Array into the ArrayList ?[/color]

        I haven't seen any answers addressing this - use AddRange(IColle ction).

        --
        Jon Skeet - <skeet@pobox.co m>
        Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

        If replying to the group, please do not mail me too

        Comment

        • ORC

          #5
          Re: ArrayList and System.Array ?

          Thank you all for your great help!

          The AddRange perfectly fits my needs, but leads me to another question: is
          it possible to add a part of a SystemArray to the ArrayList e.g. from index
          0 to index n ?

          Thanks
          Ole

          "Jon Skeet [C# MVP]" <skeet@pobox.co m> wrote in message
          news:MPG.1c1acf 2dd1ce133998ba3 b@msnews.micros oft.com...[color=blue]
          > ORC <orc@sol.dk> wrote:[color=green]
          > > How to create an ArrayList from a System.Array[/color]
          >
          > As others have said, the constructor which takes an ICollection.
          >[color=green]
          > > or inserting the System.Array into the ArrayList ?[/color]
          >
          > I haven't seen any answers addressing this - use AddRange(IColle ction).
          >
          > --
          > Jon Skeet - <skeet@pobox.co m>
          > http://www.pobox.com/~skeet
          > If replying to the group, please do not mail me too[/color]


          Comment

          • Nicholas Paldino [.NET/C# MVP]

            #6
            Re: ArrayList and System.Array ?

            Ole,

            No, it is not. The simplest way to do this would be to copy the
            elements you want to add out to another array, then call AddRange, passing
            that in.

            Hope this helps.


            --
            - Nicholas Paldino [.NET/C# MVP]
            - mvp@spam.guard. caspershouse.co m
            "ORC" <orc@sol.dk> wrote in message
            news:%23TOF7cX2 EHA.3640@tk2msf tngp13.phx.gbl. ..[color=blue]
            > Thank you all for your great help!
            >
            > The AddRange perfectly fits my needs, but leads me to another question: is
            > it possible to add a part of a SystemArray to the ArrayList e.g. from
            > index
            > 0 to index n ?
            >
            > Thanks
            > Ole
            >
            > "Jon Skeet [C# MVP]" <skeet@pobox.co m> wrote in message
            > news:MPG.1c1acf 2dd1ce133998ba3 b@msnews.micros oft.com...[color=green]
            >> ORC <orc@sol.dk> wrote:[color=darkred]
            >> > How to create an ArrayList from a System.Array[/color]
            >>
            >> As others have said, the constructor which takes an ICollection.
            >>[color=darkred]
            >> > or inserting the System.Array into the ArrayList ?[/color]
            >>
            >> I haven't seen any answers addressing this - use AddRange(IColle ction).
            >>
            >> --
            >> Jon Skeet - <skeet@pobox.co m>
            >> http://www.pobox.com/~skeet
            >> If replying to the group, please do not mail me too[/color]
            >
            >[/color]


            Comment

            • ORC

              #7
              Re: ArrayList and System.Array ?

              OK thanks! What about using an ArrayList in a call to a native DLL instead
              off using a System.Array - will that be possible and is .NET able to marshal
              it automatically?

              Thanks,
              Ole

              "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote in
              message news:u7LSLmX2EH A.3244@TK2MSFTN GP11.phx.gbl...[color=blue]
              > Ole,
              >
              > No, it is not. The simplest way to do this would be to copy the
              > elements you want to add out to another array, then call AddRange, passing
              > that in.
              >
              > Hope this helps.
              >
              >
              > --
              > - Nicholas Paldino [.NET/C# MVP]
              > - mvp@spam.guard. caspershouse.co m
              > "ORC" <orc@sol.dk> wrote in message
              > news:%23TOF7cX2 EHA.3640@tk2msf tngp13.phx.gbl. ..[color=green]
              > > Thank you all for your great help!
              > >
              > > The AddRange perfectly fits my needs, but leads me to another question:[/color][/color]
              is[color=blue][color=green]
              > > it possible to add a part of a SystemArray to the ArrayList e.g. from
              > > index
              > > 0 to index n ?
              > >
              > > Thanks
              > > Ole
              > >
              > > "Jon Skeet [C# MVP]" <skeet@pobox.co m> wrote in message
              > > news:MPG.1c1acf 2dd1ce133998ba3 b@msnews.micros oft.com...[color=darkred]
              > >> ORC <orc@sol.dk> wrote:
              > >> > How to create an ArrayList from a System.Array
              > >>
              > >> As others have said, the constructor which takes an ICollection.
              > >>
              > >> > or inserting the System.Array into the ArrayList ?
              > >>
              > >> I haven't seen any answers addressing this - use AddRange(IColle ction).
              > >>
              > >> --
              > >> Jon Skeet - <skeet@pobox.co m>
              > >> http://www.pobox.com/~skeet
              > >> If replying to the group, please do not mail me too[/color]
              > >
              > >[/color]
              >
              >[/color]


              Comment

              • ORC

                #8
                Re: ArrayList and System.Array ?

                I will start a new thread with my last question.


                "ORC" <orc@sol.dk> wrote in message
                news:uoLPYJY2EH A.1300@TK2MSFTN GP14.phx.gbl...[color=blue]
                > OK thanks! What about using an ArrayList in a call to a native DLL instead
                > off using a System.Array - will that be possible and is .NET able to[/color]
                marshal[color=blue]
                > it automatically?
                >
                > Thanks,
                > Ole
                >
                > "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote[/color]
                in[color=blue]
                > message news:u7LSLmX2EH A.3244@TK2MSFTN GP11.phx.gbl...[color=green]
                > > Ole,
                > >
                > > No, it is not. The simplest way to do this would be to copy the
                > > elements you want to add out to another array, then call AddRange,[/color][/color]
                passing[color=blue][color=green]
                > > that in.
                > >
                > > Hope this helps.
                > >
                > >
                > > --
                > > - Nicholas Paldino [.NET/C# MVP]
                > > - mvp@spam.guard. caspershouse.co m
                > > "ORC" <orc@sol.dk> wrote in message
                > > news:%23TOF7cX2 EHA.3640@tk2msf tngp13.phx.gbl. ..[color=darkred]
                > > > Thank you all for your great help!
                > > >
                > > > The AddRange perfectly fits my needs, but leads me to another[/color][/color][/color]
                question:[color=blue]
                > is[color=green][color=darkred]
                > > > it possible to add a part of a SystemArray to the ArrayList e.g. from
                > > > index
                > > > 0 to index n ?
                > > >
                > > > Thanks
                > > > Ole
                > > >
                > > > "Jon Skeet [C# MVP]" <skeet@pobox.co m> wrote in message
                > > > news:MPG.1c1acf 2dd1ce133998ba3 b@msnews.micros oft.com...
                > > >> ORC <orc@sol.dk> wrote:
                > > >> > How to create an ArrayList from a System.Array
                > > >>
                > > >> As others have said, the constructor which takes an ICollection.
                > > >>
                > > >> > or inserting the System.Array into the ArrayList ?
                > > >>
                > > >> I haven't seen any answers addressing this - use[/color][/color][/color]
                AddRange(IColle ction).[color=blue][color=green][color=darkred]
                > > >>
                > > >> --
                > > >> Jon Skeet - <skeet@pobox.co m>
                > > >> http://www.pobox.com/~skeet
                > > >> If replying to the group, please do not mail me too
                > > >
                > > >[/color]
                > >
                > >[/color]
                >
                >[/color]


                Comment

                Working...