I'm writing a custom class which implements IDictionary, and I'm not sure what to do about CopyTo. Should each element just be copied to the target array (shallow copy), or should I make a copy/clone of each element then place it in the target array (deep copy)?
Implementing ICollection.CopyTo in C#: deep or shallow copy?
1.5k views Asked by Eric Dand At
1
There are 1 answers
Related Questions in C#
- How to call a C language function from x86 assembly code?
- What does: "char *argv[]" mean?
- User input sanitization program, which takes a specific amount of arguments and passes the execution to a bash script
- How to crop a BMP image in half using C
- How can I get the difference in minutes between two dates and hours?
- Why will this code compile although it defines two variables with the same name?
- Compiling eBPF program in Docker fails due to missing '__u64' type
- Why can't I use the file pointer after the first read attempt fails?
- #include Header files in C with definition too
- OpenCV2 on CLion
- What is causing the store latency in this program?
- How to refer to the filepath of test data in test sourcecode?
- 9 Digit Addresses in Hexadecimal System in MacOS
- My server TCP doesn't receive messages from the client in C
- Printing the characters obtained from the array s using printf?
Related Questions in COPY
- What is correct way to copy struct instance with fields in Go?
- On paste StartFragment - EndFragment Postman issue
- Copy paste a single value from within a cell to another cell
- Char array, char pointer, works in one case but not the other?
- Macro to copy, rename and organize a template worksheet
- Stored procedure with copy statement keeps running when called
- How can creation times be preserved while copying on Mac?
- Automate buildozer with windows bat file and ubuntu script
- If Cell contains specific text in col A copy cell from Col C into Col F stacked
- Why do I have a 403 error when trying to save a website
- SSRS Report - Graph when exported is compressed into a graphic
- Need to copy multiple cells in the same row of data from one sheet to another when a Checkbox is checked
- Is there a way to set an open workbook as a source without having the file name?
- How do you deep copy a variant of pointers in C++?
- Python Copy dictionary
Related Questions in CLONE
- Leetcode 1255-recursion and backtracking
- Forking vs Cloning in GitHub
- Trying to run a "uber clone" from github in react native ( vs code )
- I can“t clone my github repository with a ssh key
- Laravel 9 $model->replicate() is not immutable
- Cloning resources group into another
- A way to declare and clone a cloneable (#[derive(Clone)]) struct with a type parameter and a field that is an Arc of an uncloneable type in Rust?
- GIT repo with submodule that can point to two different repositories
- Site Not Found Error After Deployed in Firebase
- PHP Cloning an object when a reference exists breaks the clone
- Git how to pull the update from original repository and keep my own changes
- git svn clone does not grab a branch not in stdlayout
- PDO clone a record then open cloned record to edit
- Problem in Hover Animation in a ReactJS Component
- How to clone an element on click in React.js
Related Questions in INTERFACE-IMPLEMENTATION
- why can't we implement two interfaces that have methods with identical signature which one of them has a default implementation in java?
- How to implement C# interface in Python
- C# record and implement interface with nullable
- Issues implementing a check and erase on VBA coding for sells control
- Access Virtual Function In Interface Directly From Implemented Class
- Explicit Cast From Type to Not Implemented Interface Compiles but Fails in Runtime
- System.NotImplementedException after trying to run canvas.DrawText in .NET MAUI
- How to auto-generate an interface implementation in vscode
- Blazor component as partial class doesn't see implemented interface method from inside its view
- Return types not matching
- Implementing interfaces in a method using lambda (JAVA)
- How to use an interface where one module implements the functionality and another is calling it for the result in Kotlin
- ISupportInitialize in WinForms controls: explicit or implicit implementation?
- .NET Core - what is the best practice of implementing an interface due to conditions at runtime
- Where to put implementation of frequently used interface in Clean Architecture
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
The implementation is not defined by the contract, however all the generic collections appear to do a shallow copy (see http://referencesource.microsoft.com/#q=List.CopyTo). It makes sense, as there is no defined way to deep copy any
object, which would be part of theCopyToimplementation.It depends on your scenario, if you do not intend to use this method at all, consider not implementing it and throwing a
NotSupportedException. If others will use your collection, implement a shallow copy to align with the standard .NET library. If you need a deep copy method, add it as a separate method, (potentially by implementingICloneable).