Error message is clear, String.Chars
property is a read-only. You can't assing it.
Here how it's defined;
public char this[
int index
] { get; }
As you can see, there is no set
accessor.
You can use String.Remove
and String.Insert
methods for this. Here an example on LINQPad;
string s = "abc";
s = s.Remove(1, 1).Insert(1, "d");
s.Dump(); //adc
Remember, string
is immutable type. You can't change them. It can't be modified after it is created. Even if you think you change them, you actually create new strings object.
As an alternative, you can use StringBuilder
class which represents mutable strings since StringBuilder.Chars
property has get and set accessors.
var sb = new StringBuilder("abc");
sb[1] = 'd';
sb.Dump(); // adc