Here is another simple question (I'm asking them because I couldn't find a way by myself):

Suppose I have a string

x = "Daniweb"

When I try to update an element like :

x[3] = k

The Visual Studio says it is read only and gives error.

How can I solve this problem?
Thanks..

Recommended Answers

Strings are immutable in C#. If you want something more like an array, use a StringBuilder object:

var x = new StringBuilder("Daniweb");

x[3] = 'k';

Console.WriteLine(x.ToString());
Jump to Post

All 2 Replies

Strings are immutable in C#. If you want something more like an array, use a StringBuilder object:

var x = new StringBuilder("Daniweb");

x[3] = 'k';

Console.WriteLine(x.ToString());

Thank you! That really helped!

Be a part of the DaniWeb community

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