string.Length vs string.ToCharArray().Length

c#, string

Solution

No difference : have a look the method code with reflector : it will allocate a char[] based on the length of the string.

Problem

I'm cleaning up some old code that's repeatedly doing `myString.ToCharArray().Length`; instead of `myString.Length`. Before I refactor `ToCharArray()` out, are there any circumstances where doing so would result in different behavior?

Original source