c0r*_*0rd 1 c# string stringbuilder
我想重复.-40次并将其保存到string使用中StringBuilder
为什么这不起作用?
string result = new StringBuilder("").Append(".-",0,40).ToString();
Run Code Online (Sandbox Code Playgroud)
我知道其他解决方案,但我想使用StringBuilder
那种方法不符合你的想法.2个int参数指定要追加的子字符串的起始索引和长度.
StringBuilder确实有你想要的方法:它被称为Insert:
sb.Insert(0, ".-", 40);
Run Code Online (Sandbox Code Playgroud)