153k views
2 votes
C# strings are immutable (once a string is initialized it cannot be changed). (T/F)

User PandaWood
by
7.9k points

1 Answer

3 votes

Final answer:

True. C# strings are immutable, which means once a string is initialized, it cannot be changed.

Step-by-step explanation:

C# strings are immutable (once a string is initialized it cannot be changed). True.

In C#, once a string is created, it cannot be modified. When you perform an operation that seems to modify a string, such as concatenation or replacing characters, a new string is actually created. The original string remains unchanged. This immutability is an important feature of C# strings.

For example:

string originalString = "Hello,";
string modifiedString = originalString + " World!";

// originalString is still "Hello,"
// modifiedString is "Hello, World!"

User KenIchi
by
8.4k points