Avatar ·

Best way to repeat a character in a string C#

Hello everyone! I'm new to C# and came across a task that seems simple, but I'm not sure how to solve it correctly. I need to create a string consisting of a repeating character. For example, I want to get a string of 10 'X' characters — "XXXXXXXXXX". Or, for example, to format output, make a separator of 50 hyphens. I know I can do this using a `for` or `while` loop, building the string with `StringBuilder` or just concatenation. But it seems too cumbersome for such a simple task. Example of my current solution: ```csharp string result = ""; for (int i = 0; i < 10; i++) { result += "X"; } ``` But I've heard that string concatenation in a loop is bad practice due to performance. Using `StringBuilder` seems more correct, but