logo CodeStepByStep logo

RepeatString

Language/Type: C# recursion
Related Links:

Write a recursive method named RepeatString that accepts a string and an integer n as parameters and that returns the string concatenated n times. For example, the call of RepeatString("hello", 3) returns "hellohellohello". Do not use any loops; you must use recursion.

Constraints: Your method should throw an ArgumentException if passed any negative value for n. You are not allowed to construct any structured objects other than strings (no array, List, Scanner, etc.) and you may not use any loops to solve this problem; you must use recursion.

Method: Write a C# method as described, not a complete program or class.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.