Possible Duplicate:
Is there an easy way to return a string repeated X number of times?
In Python you can multiply sequences like this
fivespaces= ' ' * 5
Is there any built-in equivalent for this in C#? (without operator overloads or class extensions)
If it's just a string then you can return multiples by passing in a count to string()
var fivespaces = new string(" ", 5);
In the case where you want a collection of something else like a custom type, you can use Enumerable.Repeat to get a collection:
var items = Enumerable.Repeat(new SomeModel(), 5);
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