469,646 Members | 1,298 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,646 developers. It's quick & easy.

Copy of List<>


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
2 2477

"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
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.

Similar topics

14 posts views Thread by Dave | last post: by
reply views Thread by Iron Moped | last post: by
7 posts views Thread by Andrew Robinson | last post: by
35 posts views Thread by Lee Crabtree | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.