更新时间:2023-12-04 13:45:04
它应该给编译器错误,因为您试图在此处将string
分配给char
:
It should give compiler error because you are trying to assign a string
to char
here:
textBox1.Text[1] = "welcome to ***";
Text
属性的类型为string
,当您在string
上使用索引器时,它会在该位置提供char
.而且字符串是不可变的,因此您不能在不创建新字符串的情况下真正更改特定位置的字符.
Text
property is of type string
, when you use indexer on a string
it gives you the char
at that position. And also string is immutable so you can't really change a character at specific position without creating a new string.
您应该像这样直接设置Text
:
You should set the Text
directly like this:
textBox1.Text = "welcome to ***";
或者,如果字符串数组中有多行,则应设置Lines属性:
Or if you have more than one line in an array of string you should set the Lines property:
var lines = new [] { "foo", "bar" };
textBox1.Lines = lines;