Note You can see that the character array contains the same characters as the original string.
' String input value.
Dim value As String = "abcd"' Call ToCharArray function.
Dim array() As Char = value.ToCharArray' Loop over Char array.For Each element As Char In array
A discussion. Char arrays are mutable and String instances are not. This means we can modify individual characters without changing the rest of the string. This can improve performance.
Note You can change the individual characters in a Char array without copying the entire set of characters again.
A summary. ToCharArray converts strings to their equivalent Char arrays. You cannot cast the String to a Char array. You must convert it—the best way is usually with ToCharArray.
Dot Net Perls is a collection of tested code examples. Pages are continually updated to stay current, with code correctness a top priority.
Sam Allen is passionate about computer languages. In the past, his work has been recommended by Apple and Microsoft and he has studied computers at a selective university in the United States.