-4

Let's say we need to output 1000 # symbols in one line without loops or recursion. And surely without making a line of code with 1000 chars there.

The noob solution that comes to mind is...

string s = "#";
s = s+s+s+s+s+s+s+s+s+s;
s = s+s+s+s+s+s+s+s+s+s;
s = s+s+s+s+s+s+s+s+s+s;
Console.WriteLine(s);

Are there any others?

Uk rain troll
  • 1
  • 1
  • 13

1 Answers1

7

var repeatedString = new string('#', 1000);

Ruskin
  • 1,504
  • 13
  • 25
  • Isn't that a kind of a loop anyways? – Uk rain troll Jun 09 '15 at 03:11
  • That's why I asked, "what kind of loop that he avoid". But it's much better than his "simplest solution" :) – Heinz Siahaan Jun 09 '15 at 03:13
  • Well I am no IL expert but it's not translated to a loop when I investigated the IL, you can argue that it is but I will stay away from that discussion :). Also, using + for a string concatenation is not good for performance as strings are immutable (https://support.microsoft.com/en-us/kb/306822) – Ruskin Jun 09 '15 at 03:21
  • Well, I asked this question more for fun and also to learn something. Thank you for your answer. – Uk rain troll Jun 09 '15 at 03:32