Re: Best way to clone an ArrayList?
- From: "Howard Swope" <howardsnewsATspitzincDOTcom>
- Date: Fri, 15 Jul 2005 11:44:10 -0400
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
.
- Follow-Ups:
- Re: Best way to clone an ArrayList?
- From: Chris Bellini
- Re: Best way to clone an ArrayList?
- References:
- Best way to clone an ArrayList?
- From: Chris Bellini
- Best way to clone an ArrayList?
- Prev by Date: Re: Excel/PowerPoint Quit event
- Next by Date: Re: noob question: how do i access the object sender properties
- Previous by thread: RE: Best way to clone an ArrayList?
- Next by thread: Re: Best way to clone an ArrayList?
- Index(es):
Relevant Pages
|