你总是可以写一个扩展方法:
public static class StringExtensions{
public static string Prefix(this string str, string prefix){
return prefix + str;
}
}
var newString = "Bean".Prefix("Mr. ");
Run Code Online (Sandbox Code Playgroud)
它不是语法糖,但很容易.虽然它并不比已经建议的更简单.
在C#中没有= +运算符,但幸运的是OO来到这里救援:
string value = "Jamie";
value = value.Insert(0, "Hi ");
Run Code Online (Sandbox Code Playgroud)
有关string.Insert的更多信息:http: //msdn.microsoft.com/en-us/library/system.string.insert.aspx
我同意a = b + a似乎是最明智的答案.它读取比使用string更好.插入是肯定的.
| 归档时间: |
|
| 查看次数: |
325 次 |
| 最近记录: |