5
Answers

Copy Object

Lars Persson

Lars Persson

12y
1.3k
1
I have List-control of objects.

I want find a certain object and save it away for later use.

To do this, I used a foreach-loop and tried to copy the object I found into a new object-variable.

Something like:

Book temporary = null; //Reference to Book-object

foreach (Book B in BookList)
 if (txtBox1.Text.Equals(B.ID.ToString()))
 temporary = B;

But that doesn´t seem to work.

How can I do this?
Answers (5)