Back to questions
JuniorTheoryCommon
What does the program print (lines separated by spaces)?
string s = "abc";
s.ToUpper();
Console.WriteLine(s);
s = s.ToUpper();
Console.WriteLine(s);abc ABC
- Expecting
ABCon the first line:ToUpperdoes not changes; it returns a new string, and a call without an assignment loses it. - Expecting
s = s.ToUpper()to fail or do nothing: the string is immutable, but the variable can take a new string at any time.
- Which other string methods behave like
ToUpperhere? - What does the compiler say about
s[0] = 'A';?