I want to do this:
string s = "abc";
s[1] = 'x';
and s will become “axc”. However, it seems that string[i] only has a getter and has no setter. The compiler gives me the following error:
“Property or indexer
‘string.this[int]’ cannot be assigned
to — it is read only”
I guess I could make a loop and change the char i want. but i was just wondering if there is an easy way to do it? And why there isn’t a setter for string[i]?
Thanks in advance.
Strings are immutable, so you have to make a
char[]array, change it, then make it back into a string: