Voglio fare questo:C'è un modo semplice per cambiare un carattere in una stringa in C#?
string s = "abc";
s[1] = 'x';
e s diventerà "AXC". Tuttavia, sembra che la stringa [i] abbia solo un getter e non abbia setter. Il compilatore mi dà il seguente errore:
"Property or indexer 'string.this[int]' cannot be assigned to -- it is read only"
Credo di poter creare un ciclo e modificare il carattere desiderato. ma mi stavo chiedendo se c'è un modo semplice per farlo? E perché non c'è un setter per string [i]?
Grazie in anticipo.
Le stringhe in C# sono immutabili, quindi non è possibile farlo. – ChrisF