Hi
Given the following code example
// It returns the altered argument as a new instance of string.
public static string BetterThanPassTheReference(string argument)
{ return argument + " ABCDE"; }
I might be missing something obvious here but how is this method returning a new instance of string?
Could this be a shorthand notation for the following:-
String returnArguement = arguement + "ABCDE";
return returnArguement;
Regards
How is this returning a new instance?
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

VulpesRank #55 · 29.2K reputationPosted Aug 16, 2012, 11:17 AM EDT
So, when you concatenate two strings, a new instance of string is created which consists of the characters of the first string followed by the characters of the second.
Similarly, all the methods of the string class which might appear to be altering a string are in fact returning a new instance of it.
VulpesRank #55 · 29.2K reputationPosted Aug 16, 2012, 11:32 AM EDT
Also, most of the structs in the .NET framework are immutable : Int32, Char, Boolean, Double, DateTime etc.