.Net - Frequently Asked QuestionsDifference between System.Array.CopyTo and System.Array.Clone()
The System.Array.CopyTo method copies the elements into another pre-existing array starting from a given index. In this case the destination array need to already exist. More over, the target Object needs to be sufficient to hold all the elements in the source array from the index you specify as the destination. When perform CopyTo() method both arrays must be single dimensional.
The System.Array.Clone() method returns a new array object, which means that the destination array need not exist yet since a new one is created from scratch with containing all the elements in the original array. The Clone() method works on both single and multi-dimensional arrays.
Performance wise System.Array.CopyTo is faster than Clone when copying to array of same type.
Shallow copy and Deep copyIn .Net Shallow copy and deep copy are used for copying data between objects. Shallow copying is creating a new object and then copying the non static fields of the current object to the new object. If the field is a value type, a bit by bit copy of the field is performed. While Deep copy is creating a new object and then copying the non-static fields of the current object to the new object. If a field is a value type, a bit by bit copy of the field is performed. More about... Difference between Shallow copy and Deep copy
Array ExampleArrays are using for store similar data types grouping as a single unit. We can access Array elements by its numeric index. The array indexes start at zero. More about.... Array
- Can you store multiple data types in an Array
- What is meant by Hash Code
- Is string a value type or a reference type
- Difference between parse and tryparse
- What are the type of Errors
- What is anonymous type ?
- Difference between Singleton and a Static Class
- Difference between Properties and Fields
- What does the [Flags] Enum Attribute Mean?