开发者

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

开发者 https://www.devze.com 2023-04-04 17:31 出处:网络
I\'m facing this abnormal situation. The following code doesn\'t work properly: string temp = \"heythere\";

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

精彩评论

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