Can any one explain why the output of this code is only ‘hello’ and what this code means?
( 0, characterArray, 0, characterArray.Length );
The output is showing:
The character array is: hello
The code follows:
string string1 = 'hello there'; char[] characterArray = new char[ 5 ]; string1.CopyTo( 0, characterArray, 0, characterArray.Length ); Console.Write( '\nThe character array is: ' ); for ( int i = 0; i < characterArray.Length; i++ ) Console.Write( characterArray[ i ] );
It’s because your array is only set for 5 characters. Expand it to 11 and it will work.
Here is what the Copyto is:
Taken from: http://msdn.microsoft.com/en-us/library/system.string.copyto.aspx