开发者

textBox1.Text.Insert(...) method doesn't work

I'm facing this abnormal situation. The following code doesn't work properly:

        string temp = "heythere";
        Console.WriteLine(temp);
        temp.Insert(3, "hello");
        Console.WriteLine(temp);

Isn't it supposed to output like "heyhellothere" ? But 开发者_如何学Cit does "heyrehere" (no change).


Strings are immutable, they don't change in-place. Try:

string temp = "heythere";
Console.WriteLine(temp);
temp = temp.Insert(3, "hello");
Console.WriteLine(temp);


Or, your can try this

string temp = "heythere";
Console.WriteLine(temp.Insert(3, "hello"));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜