0

So, I've been learning JavaScript recently and now have been over the past two weeks having to learn C# too. I have converted a block of code from JS to C#. The answer is in a form of an array containing integers.

Console.WriteLine(results[i]); returns

12
457
7
99

However, I would like to show this on one line, but Console.Write(results[i]); combines the integers and returns

12457799

and I would it to show:

12 457 7 99

I've tried some rudimentary ways to fix it but have been unsuccessful.

Any tips would be appreciated. Cheers.

GSerg
  • 76,472
  • 17
  • 159
  • 346
James
  • 3
  • 1
  • 1
    Without the loop, you can work with `String.Join(" ", results);` – Yong Shun Jun 09 '22 at 08:24
  • 2
    `Console.Write(string.Join(" ", results));` prints out entire `result` array while separating items with spaces – Dmitry Bychenko Jun 09 '22 at 08:24
  • OP's solution actually is pretty close. You can do a `Console.Write(results[i] + " ");` since the functions accepts a `string`, so as long it's a string you can format it as you want. But `String.Join` indeed is a better solution since it doesn't add space after the last element, which usually we don't want to do when we try to print multiple elements. For example, a `Console.Write(results[i] + ",");` solution will result in `12,457,7,99,` being printed. – Xiang Wei Huang Jun 09 '22 at 08:52

0 Answers0