小编Igo*_*goy的帖子

为什么字符串的索引器是只读的?

当我尝试分配给字符串中的单个字符时,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)

.net c# string

2
推荐指数
1
解决办法
7108
查看次数

标签 统计

.net ×1

c# ×1

string ×1