当我尝试分配给字符串中的单个字符时,s[i] = c出现编译器错误:
string s = "bcc";
s[0] = 'a'; // shows compile time error - indexer cannot be assigned - it's readonly
Run Code Online (Sandbox Code Playgroud)
但是这有效:
s.ToCharArray()[0] = 'a';
Run Code Online (Sandbox Code Playgroud)
我们也可以将字符串完全分配给acc:
s = "acc"
Run Code Online (Sandbox Code Playgroud)