I want to create a string repeating the same seqeuence n-times.
How I do this:
var sequence = "\t";
var indent = string.Empty;
for (var i = 0; i < n; i++)
{
indent += sequence;
}
Is there a neat LINQ equivalent to accomplish the same result?
You can use Enumerable.Repeat
in String.Concat
:
string intend = String.Concat(Enumerable.Repeat(sequence, n));
If you just want to repeat a single character you should prefer the String
-constructor:
string intend = new String('\t', n);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With