By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,290 Members | 1,481 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,290 IT Pros & Developers. It's quick & easy.

Copy of List<>

P: n/a

I am not sure how to fix this problem I've stumbled into...

I have a list<> of an interface type. I need to pass that list to a
method that adds more objects to the list.

But, eventually, I need to get back to the original list<> object.

---

In other words; let's say I start with an List<> of 3 objects. I call a
method that adds 5 more objects to that List<>. I continue on with my
work. Once I'm done, I need to get back to my original list of 3 objects.

My first guess is I to use a copy of my List object when I call the
appender method. But, I'm not sure how you can copy a List<> object.

--Brian
Nov 29 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"Brian Pelton" <no@email.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
My first guess is I to use a copy of my List object when I call the
appender method. But, I'm not sure how you can copy a List<> object.


Can't you just pass the original list you're cloning as an actual parameter
argument to the ctor?
List<string> workingNames = new List<string>(names);

--
Mickey Williams
C# MVP, MCT, Author
http://www.servergeek.com/blogs/mickey
Nov 29 '05 #2

P: n/a
That is awesome!

Yes that works! You saved me from doing a foreach... and adding the
elements one at a time into a new List.

Thanks a million!
--Brian

Mickey Williams [C# MVP] wrote:
"Brian Pelton" <no@email.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...

My first guess is I to use a copy of my List object when I call the
appender method. But, I'm not sure how you can copy a List<> object.

Can't you just pass the original list you're cloning as an actual parameter
argument to the ctor?
List<string> workingNames = new List<string>(names);

Nov 29 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.