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?

Recommended Answers

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';


Thank you! That really helped!

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.