+ 9

How to solve this error?

I want change a char of a string but I am getting error. https://code.sololearn.com/c29mJ7Eapi3e/?ref=app I am not understanding why I am getting this error and how to solve this.Please help me. Thanks in advance.I am new in c#.

17th Aug 2020, 5:36 PM
The future is now thanks to science
The future is now thanks to science - avatar
13 Respuestas
+ 6
copy the string to char array,then u can change any character ex: string str = "any string"; char [] arr = str.ToCharArray(); arr[0] = 'P';
17th Aug 2020, 5:49 PM
durian
durian - avatar
+ 6
The CS0200 error is caused when you try to assign a value to a variable that can only be read and not changed. To fix the CS0200 error you will need to find an alternative way of achieving the desired result. Same thing from stackoverflow https://stackoverflow.com/questions/22093976/property-or-indexer-string-thisint-cannot-be-assigned-to-its-read-only
17th Aug 2020, 5:54 PM
vaibhav
vaibhav - avatar
+ 4
Samsil Arefeen try this take out lines 21 and 22 replace with: String x = a.Replace("e", "v"); Console.WriteLine(x); This is similar to Java String x = a.replaceAll("e","v"); The first letter "e" is what letter will be changed throughout the sentence and the all the "e"s will become "v"s
17th Aug 2020, 6:19 PM
BroFar
BroFar - avatar
+ 3
char[ ] a = Console.ReadLine().ToArray(); a[2] = 'v'; Console.WriteLine(a);
19th Aug 2020, 8:01 AM
Fatbardh Hoxhaj
Fatbardh Hoxhaj - avatar
+ 1
string is read only
17th Aug 2020, 5:44 PM
durian
durian - avatar
+ 1
string is immutable, it cannot be changed after it is created, you can only create a new copy with the desired changes.
17th Aug 2020, 5:46 PM
Bahhaⵣ
Bahhaⵣ - avatar
0
So any other way to change a char of a string?
17th Aug 2020, 5:45 PM
The future is now thanks to science
The future is now thanks to science - avatar
17th Aug 2020, 5:49 PM
The future is now thanks to science
The future is now thanks to science - avatar
0
C# != C++ they are mutable in C++
17th Aug 2020, 5:52 PM
Bahhaⵣ
Bahhaⵣ - avatar
0
It works Lily Mea . Thanks everyone for all of your contribution and help.
17th Aug 2020, 5:54 PM
The future is now thanks to science
The future is now thanks to science - avatar
0
Which error?
19th Aug 2020, 5:29 AM
kinnari patel
kinnari patel - avatar
- 2
The body tag follows the head tag. All visual-structural elements are contained within the body tag. Headings, paragraphs, lists, quotes, images, and links are just a few of the elements that can be contained within the body tag
19th Aug 2020, 10:38 AM
RAMAN DEEP
RAMAN DEEP - avatar