Re: Best way to clone an ArrayList?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Reply in text:

"Chris Bellini" <chris-hatesspam@xxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
message news:etOkg8UiFHA.3656@xxxxxxxxxxxxxxxxxxxxxxx
>I was just looking for some opinions on the best way to clone an ArrayList
>object. For example, if class A contains an ArrayList, what would be the
>best way to make a copy of it for class B (but not using the class
>constructors):
>
> class A
> {
> public A()
> {
> // constructor stuff goes here
> }
>
> public void DoStuff()
> {
> ArrayList arrTPB = new ArrayList();
>
> arrTPB.Add("Ricky");
> arrTPB.Add("Julian");
> arrTPB.Add("Bubbles");
>
> // new B object
> B myB = new B();
>
> // copy arrTPB from class A to arrNames of myB
> // ???

myB.PutNames(arrTPB);
> }
> }
>
>
> class B
> {
> public ArrayList arrNames;
>
> public B()
> {
> arrNames = new ArrayList();
> // other constructor stuff goes here
> }

public PutNames(ArrayList al)
{
foreach (object obj in ArrayList)
{
if (!obj is string)
continue;
arrNames.Add(obj);
}
}
> }
>
> Thanks in advance.
>
>
>
> Chris


.



Relevant Pages

  • Re: Heres The Deal
    ... > argument going and trying to force me to have the exact same opinions ... > pointless. ... Prev by Date: ...
    (alt.guitar.bass)
  • Re: Best way to clone an ArrayList?
    ... > I was just looking for some opinions on the best way to clone an ... > ArrayList object. ... Prev by Date: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: OT Blast....
    ... I have set up a forum where people's opinions can be expressed. ... Chris ... Prev by Date: ...
    (uk.sci.weather)
  • Re: Massive blast hits UK fuel depot -- fuel prices of course will go up now
    ... I have set up a forum where people can express their opinions. ... Chris ... Prev by Date: ...
    (uk.politics.misc)
  • Re: Archiving database
    ... or I try not using the last line and having the clone run the script ... I just have an import statement with no options in the import script. ... Prev by Date: ...
    (comp.databases.filemaker)