If the method parameter is a reference type I can modify it with a side effect without ref, right?
And string is a reference type, right?
So, why this: ideone.com/IEWpcEmr two calls do not behave in the same way? - Any help to explain this?
Explanation taken from:
Manipulating Strings in C# at C# Online.NET (CSharp-Online.NET)
What makes string types really interesting is that in .NET strings are immutable—the contents of the buffer can't be changed. Languages like C# enable you to treat your string variable as a changeable type. For example, they let you append another string to the string in your variable. However, this is an illusion provided by the compiler. In reality, when you change the contents of your string, the compiler asks the .NET runtime to create a brand-new string object.
@QuackWare Thank you!
so
String s = "A";
is equivalent to
String s = new String("A");
It seems to more understandable now, thanks!
PS: also the csharp-online.net looks cool!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks