我试图在一个基于项深度的字符串之前插入一定数量的缩进,我想知道是否有一种方法可以重复X次返回一个字符串.例:
string indent = "---";
Console.WriteLine(indent.Repeat(0)); //would print nothing.
Console.WriteLine(indent.Repeat(1)); //would print "---".
Console.WriteLine(indent.Repeat(2)); //would print "------".
Console.WriteLine(indent.Repeat(3)); //would print "---------".
Run Code Online (Sandbox Code Playgroud)