c# write a string x times code example
Example 1: c# repeat string x times
string result = new String('-', 5);
Output: -----
Example 2: how to write a method that returns a string that copies itself times n
public static String repeat(String s, int n) { StringBuilder sb = new StringBuilder(str.length() * n); for (int i = 0; i < n; i++) sb.append(s); return sb.toString();} public static void main(String[] args) { System.out.println(repeat("ha", 5));}