c# - += 使用字符串的相反操作是什么?

标签 c# string

例如我有一个

String a="Hello";
a+="World";

这会将 World 放在最后。怎么放在开头呢?

最佳答案

简单地:

string a = "Hello";
a = "World" + a;

最终,a += "World"; 只是以下语法的缩写:

a = a + "World";

如果要颠倒操作数的顺序,则不存在这样的缩写。

作为旁注 - 请记住,如果您经常这样做(在循环中等),最好考虑使用 StringBuilder 来避免很多中间 strings.

关于c# - += 使用字符串的相反操作是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16542044/

相关文章:

c# - 数据库中没有发生数据插入

c# - Unity iOS编译: Cross Compilation job Mono.WebBrowser.dll failed错误

c# - Autofac 委托(delegate)工厂,并传递容器

c# - Visual Studio : Replace all references to ConfigurationManager. AppSettings 到 CloudConfigurationManager.GetSetting 使用正则表达式

c# - 如何从 visual studio 中的文本编辑器中删除虚线?

jquery - 正则表达式,用jQuery删除字符串中的最后一个特定字符

c++ - 将变量放入字符串(arduino)

java - 如何解决StringConverter ClassCastException?

c++ - 字符串类中 c_str 函数的内存分配

c - strcmp 在我的代码中不起作用