Being new to C #, I read several tutorials. About the lines, here I read (my selection):
Strings are immutable - the contents of a string object cannot be changed after the object is created, although the syntax makes it as if you can do it. For example, when you write this code, the compiler actually creates a new string object to hold a new sequence of characters and the variable b continues to hold "h" .string b = "h"; b += "ello";
Strings are immutable - the contents of a string object cannot be changed after the object is created, although the syntax makes it as if you can do it. For example, when you write this code, the compiler actually creates a new string object to hold a new sequence of characters and the variable b continues to hold "h" .
string b = "h"; b += "ello";
But after trying the following code, it prints "hello."
string b = "h"; b += "ello"; System.Diagnostics.Debug.WriteLine(b);
So, am I misinterpreting what I am reading, or incorrect documentation? Any other option? :)
, , , , (. ). ,
string b = "h"; string d = b; d += "ello";
b - "h", += , string, d .
b
+=
string
d
, 3 strings. string "h", string "ello" , , string "", . string , , string 3, , - "", d. string, .
strings
, , , Visual Studio 2005, . .
, Visual Studio 2008:
- , . , , , b. "h" .
, , , "h" .
"h"
The documentation seems to be wrong: it d += "ello";is a shortcut tod = d + "ello";
d += "ello";
d = d + "ello";
The string object itself is immutable, but you assign a new string to the existing variable (d).
Source: https://habr.com/ru/post/1605948/More articles:Creating .so file for OpenH264 android - androidPython Decorator Self-firing - pythonHMAC-SHA1 to sign OAuth in Swift - oauthImport Swift code into Objective-C file - iosReproduce table layout in .NET winform - user-interfaceHow to choose the most efficient renderer, Canvas or WebGL - javascriptHave a command with "CanXXXX" while listening to several properties - commandAdding a class if aria-extended === true - javascriptSkipping lines of code based on available features (s) / toolbars - debuggingQQuickWidget делает бескаркасный и прозрачный QMainWindow полностью исчезающим - qtAll Articles