Go to DotNetFunda.com
 Online : 871 |  Welcome, Guest!   Login
 
Home > Interview Questions > C# Interview Questions > Differrence between Array.CopyTo() and A ...

  • Nominate yourself for "Agile Software Development using Scrum" online session for FREE, click here.

  • Download OOPS and ASP.NET Online training session video and PPT from here.

call for mock interview

C# Interview Questions

Differrence between Array.CopyTo() and Array.Clone()

Author: Syedshakeer | Posted on: 2/18/2009 5:49:12 AM | Category: C# | Views:2005 |  Print | Asked In: Many Interviews


Answer:
Both CopyTo() and Clone() make shallow copy (data is copied) and used for Single Dimension arrays.

Clone() method makes a clone of the original array. It returns an exact length array.

CopyTo() copies the elements from the original array to the destination array starting at the specified destination array index. Note that, this adds elements to an already existing array.

In VB.NET, variables has to be declared earlier, before using Clone or CopyTo methods to store the values. The difference arise on mentioning the size of the array.

While declaring the varaiable that is used for CopyTo method, it should have the size equal to or more than that of the original array.

While declaring the variable that is used for Clone method we need not mention the array size. Eventhough the array size is small, it won't show any error, rather the array size gets altered automatically on cloning. The cloned array size get created equal to the size of the source array.

If value type is used for CopyTo/Clone any change in the values made on them will not get reflected on the original whereas on reference type the change gets reflected.

Below is the code which would throw some light on your understanding.

Interesting?   Share and Bookmark this


Navigate to:

 Submit Interview Questions

Most Important Questions in Interview ...

An automatic commit ocurrs under the following circumstances ...

Random Interview Questions
Help: If for some reason you are getting the same question by clicking Next Question or Previous Question, Try clicking Categories link above.

Related interview questions



Advertisement

About Us | The Team | Advertise | Contact Us | Feedback | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you found copied contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
All rights reserved to DotNetFunda.Com. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks.
(Best viewed in IE 6.0+ or Firefox 2.0+ at 1024 * 768 or higher)