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
Loading
VulpesPosted Aug 16, 2012, 3:17 PM
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.
VulpesPosted Aug 16, 2012, 3:32 PM
Also, most of the structs in the .NET framework are immutable : Int32, Char, Boolean, Double, DateTime etc.