Here's my string

string str = "a";

Now I use string.Remove()

str.Remove(0);
Console.WriteLine(str);

The character 'a' is still there, why is this?

Recommended Answers

All 2 Replies

Strings are immutable. When you have set a string equal to a value, that value does not change in and of itself. Rather, changes are returned in a new string object.

To see your changes, you would write something like

string str = "a";
str = str.Remove(0);
commented: like a walking textbook :) +1

Immutable huh? I'm going to have to look that one up.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.