Why on Earth would someone convert a string to a char[] before enumerating the characters in it? The regular pattern for initializing a System.Security.SecureString found all around the net follows:
SecureString secureString = new SecureString();
foreach (char c in "fizzbuzz".ToCharArray())
{
secureString.AppendChar(c);
}
Calling ToCharArray() makes no sense for me. Could someone tell whether I am wrong here?
Since string
implements IEnumerable<char>
, it's not necessary in this context. The only time you need ToCharArray
is when you actually need an array.
My guess is that most people who call ToCharArray
don't know that string
implements IEnumerable
(even though as far as I know it always has).