Is there a succinct way (i.e. not a for loop) to create a string of a specified length? Doesn't matter what is in the string.
You can use the string
constructor that takes a char
and an int
. It creates a string
instance with the char
repeated the specified number of times.
As bdukes mentions there's constructor, that takes a char and an int. That will construct a string of the given length filled with the char.
However, keep in mind, that strings are immutable in .NET, so if you want to create a specific string buffer, you should use StringBuilder
instead.
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