How do I copy items from list to list without foreach?
How do I transfer the items contained in one List to another in C# without using foreach? 9 Answers 9
How do I transfer the items contained in one List to another in C# without using foreach? 9 Answers 9
I have an array a which is constantly being updated. Let’s say a = [1,2,3,4,5]. I need to make an exact duplicate copy of a and call it b. If a were to change to [6,7,8,9,10], b should still be [1,2,3,4,5]. What is the best way to do this? I tried a for loop like: … Read more
I’m trying to copy a number of files and folders to a docker image build from my localhost. The files are like this: folder1 file1 file2 folder2 file1 file2 I’m trying to make the copy like this: COPY files/* /files/ However, all files are placed in /files/ is there a way in Docker to keep … Read more
It has always bothered me that the only way to copy a file in Java involves opening streams, declaring a buffer, reading in one file, looping through it, and writing it out to the other steam. The web is littered with similar, yet still slightly different implementations of this type of solution. Is there a … Read more
While reading up the documentation for dict.copy(), it says that it makes a shallow copy of the dictionary. Same goes for the book I am following (Beazley’s Python Reference), which says: The m.copy() method makes a shallow copy of the items contained in a mapping object and places them in a new mapping object. Consider … Read more
I want to copy the entire contents of a directory from one location to another in C#. There doesn’t appear to be a way to do this using System.IO classes without lots of recursion. There is a method in VB that we can use if we add a reference to Microsoft.VisualBasic: new Microsoft.VisualBasic.Devices.Computer(). FileSystem.CopyDirectory( sourceFolder, … Read more
Is there a function to make a copy of a PHP array to another? I have been burned a few times trying to copy PHP arrays. I want to copy an array defined inside an object to a global outside it. 19 s 19 In PHP arrays are assigned by copy, while objects are assigned … Read more
In order to duplicate an array in JavaScript: Which of the following is faster to use? Slice method var dup_array = original_array.slice(); For loop for(var i = 0, len = original_array.length; i < len; ++i) dup_array[i] = original_array[i]; I know both ways do only a shallow copy: if original_array contains references to objects, objects won’t … Read more
This question’s answers are a community effort. Edit existing answers to improve this post. It is not currently accepting new answers or interactions. What is the difference between a deep copy and a shallow copy? 3Best Answer 31
Consider the code below: DummyBean dum = new DummyBean(); dum.setDummy(“foo”); System.out.println(dum.getDummy()); // prints ‘foo’ DummyBean dumtwo = dum; System.out.println(dumtwo.getDummy()); // prints ‘foo’ dum.setDummy(“bar”); System.out.println(dumtwo.getDummy()); // prints ‘bar’ but it should print ‘foo’ So, I want to copy the dum to dumtwo and change dum without affecting the dumtwo. But the code above is not doing … Read more