Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
string s1 = "Old Value";
string s2 = s1;
s1 = "New Value";
Console.WriteLine(s2);

What will be the output printed

What I have tried:

string s1 = "Old Value";
string s2 = s1;
s1 = "New Value";
Console.WriteLine(s2);

What will be the output printed
Posted
Updated 23-Mar-18 1:56am

There is an easy way to know: just run that code and see by yourself.
 
Share this answer
 
Comments
CPallini 23-Mar-18 7:52am    
Of course :-)
5.
Patrice T 23-Mar-18 7:56am    
Thank you.
And it is minimum effort :-)
Maciej Los 23-Mar-18 15:16pm    
5ed!
In another approach, you could read the documentation Strings (C# Programming Guide) | Microsoft Docs[^] (see the "Immutability of String Objects" sections, 2nd example).
 
Share this answer
 
Comments
Patrice T 23-Mar-18 8:27am    
indeed.
Maciej Los 23-Mar-18 15:16pm    
5ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900