listBox 没有在其中显示手动字符串,而是显示 'str' 值

listBox is not displaying manual string inside it, but displaying the 'str' value

首先,那是什么鬼,我觉得没有任何表达,但我想问问各位专家:

string onUserName = msj.Substring(3);
lstMsjClient.Items.Add(onUserName + "is online now.");

这里onUserName可以在lstMsjClient里面显示,但是"is online now"不能在lstMsjClient里面显示。 所以这不是很有趣,原因是什么? 这太有趣了。

如果你使用

string msj = "One";
string onUserName = msj.Substring(3);
lstMsjClient.Items.Add(onUserName + "is online now.");

//O is 0
//n is 1
//e is 2
//after blank 3. index


Output : "is online now." 

因为 Substring(3) 表示索引从 3 开始。

如果你想要前 3 个字符,你必须使用 Substring(0,3)

试试这个代码

string msj = "OneTwoThree";
string onUserName = msj.Substring(3);
listBox1.Items.Add(onUserName + "is online now.");

Output : "TwoThreeis online now." ok?