Implementing System.String

I recently tried to do the following in C #

string str = "u r awesome";
str[0]="i";

And this will not work, because, apparently, str [i] is just not a collection, so I was wondering if the main implementation of the string is to make str [i] only be get.

Isn't that just a managed shell for char *? So why can't I set str [i]?

+5
source share
3 answers

The answers others have given regarding immutability are, of course, correct and are the "actual" cause of the problem you have.

(, ), , , :

" .NET CLR BSTR OLE Automation: , , , UTF-16, ."

" " , BSTR .

, . , , .

+3

, .NET String - ​​ , . , , , .

, , StringBuilder.

C, String const char *, , . StringBuilder char * ( ) (ToString()) String .

+8

cdhowie, , c/++

, ,

List<char> str = new List<char>("u r awesome");
str[0] = 'i';
str[2] = 'm';
Console.WriteLine(str.ToArray());
+2

All Articles