Here We use ReferenceEquals to see if two variables point to the same reference. String.Copy returns a separate, new string.
Dim value As String = "cat"' Use String.Copy to copy a string.
Dim valueCopied As String = String.Copy(value)
' The copy has a different reference.
If Not ReferenceEquals(value, valueCopied) Then
Console.WriteLine("Not same reference")
End ModuleNot same reference
CopyTo. This method has nothing in common with String.Copy. CopyTo is an instance method and it copies the string's characters to a char array.
Here We copy the first 3 characters in a string to a 3-element char array. We then use For-Each to display the array's contents.
Dim value As String = "dog"' A 3-element char array.
Dim destination(2) As Char
' Copy string to the destination array.
value.CopyTo(0, destination, 0, 3)
' Loop over the resulting char array.For Each letter As Char In destination
A summary. The String.Copy and CopyTo methods provide ways to get the contents of strings and put them in new objects. CopyTo is more useful—it helps use char arrays.