I have three Arraylists that hold strings corresponding to addresses of an
e-mail list:
ArrayList masterList
ArrayList optInToMasterList
ArrayList optOutFromMasterList
I want to know the easiest way to add all of the +contents+ of one arraylist
to another.
masterList.CopyTo (optInToMasterList) does not have the intended effect: I
end up with an array nested in an array, which is quite logical, but it
isn't what I want.
optInToMasterList.Remove(optOutFromMasterList) does not seem to work either.
I'm sure I could figure out how to .Add and .Remove what I want to using
looping structures, but I would be happiest if there's already an inbuilt
method in the Framework to help me out.
Can you help?
Thank you,
-KF
gary@garyshort.org - 17 Nov 2006 20:17 GMT
Is this the sort of thing you are looking for?
ArrayList AL1 = new ArrayList(3);
ArrayList AL2 = new ArrayList(3);
ArrayList AL3 = new ArrayList(6);
//Fill an arraylist with strings
AL1.Add("One");
AL1.Add("Two");
AL1.Add("Three");
//Fill another arraylist with strings
AL2.Add("Four");
AL2.Add("Five");
AL2.Add("Six");
//Combine the two arraylists into a third list
AL3.AddRange(AL1);
AL3.AddRange(AL2);
--
Cheers,
Gary
http://www.garyshort.org/
> I have three Arraylists that hold strings corresponding to addresses of an
> e-mail list:
[quoted text clipped - 20 lines]
> Thank you,
> -KF
Peter Bromberg [C# MVP] - 17 Nov 2006 20:19 GMT
Sometimes the brute force method will save you a lot of time, especially if
it doesn't involve a lot of code (pseudocode here):
for(int i=0;i<optIntoMasterList.Length;i++)
masterList.Add(optIntoMasterList[i]);
Cheers
Peter

Signature
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
> I have three Arraylists that hold strings corresponding to addresses of an
> e-mail list:
[quoted text clipped - 20 lines]
> Thank you,
> -KF
kenfine@nospam.nospam - 17 Nov 2006 20:58 GMT
Thanks to both of you. My application now works great and I know a lot more
about the ArrayLists's methods.
ArrayList newbies who discover this e-mail thread should note that the
ArrayList equivalent of the .Length property is ".Count".
-KF
> Sometimes the brute force method will save you a lot of time, especially
> if
[quoted text clipped - 34 lines]
>> Thank you,
>> -KF
Kevin Yu [MSFT] - 20 Nov 2006 02:18 GMT
Hi KF,
I agree with Peter. You can also use foreach statement for the loop.
Kevin Yu
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
(This posting is provided "AS IS", with no warranties, and confers no
rights.)