Thanx Mattias!
I didn't think of interning :)
But let's take this to another plane:
String* password = Console::ReadLine();
if(String::IsInterned(password) == NULL)
{
Char __pin* ps = const_cast<Char*>(PtrToStringChars(password));
while(ps && *ps != 0)
(*ps++)='0';
}
Console::WriteLine(password);
Basically i want to clear the password.
To anyone, So if String was not Interned it seems to be OK
to change it's contents although it's "immutable"?
Mattias Sjögren <ma********************@mvps.org> wrote in message news:<#D**************@TK2MSFTNGP12.phx.gbl>...
What should happen if String contents are changed like below?
The contents do change and nothing crashed or anything.
You could end up chaniging strings you don't expect. Just try
String* str = S"hello";
String* str2 = str;
Char __pin* ps = const_cast<Char*>(PtrToStringChars(str));
while(ps && *ps != 0)
(*ps++)='0';
Console::WriteLine(str);
Console::WriteLine(str2);
The CLR's string interning feature makes this even worse - you could
change strings in parts of the program you don't control.
Mattias