0

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..

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by newbiecoder
0

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());
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.