有没有办法多次插入变量而不重复?
例如:
var name = "bla";
Console.WriteLine($"foo {name:repeat:2} bar")
to print
foo blabla bar
我对插值几个特别感兴趣换行符而不是重复{Environment.NewLine}
像这样在插值掩码中多次:
$"{Environment.NewLine}{Environment.NewLine}"
public static string Repeat(this string s, int times, string separator = "")
{
return string.Join(separator, Enumerable.Repeat(s, times));
}
然后使用:
Console.WriteLine($"foo {name.Repeat(2)} bar")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)