Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Console two line output

Tags:

c#

output

console

I have this code which output some value from array, plus - in new line under value a[i]

Console.Write(a[i] + "\n-");

So it looks like this

a
-

Now i have more of Console.Write(a[i+1] + "\n-"); codes and it outputs like this

a
-b
-c
-d
-

I know why this is the case but how can I return one line up after every new line \n? So I can get this

abcd
----
like image 579
gagro Avatar asked Dec 23 '22 19:12

gagro


1 Answers

You have to output the values first, then the dashes:

Console.WriteLine(string.Join("", a)); // make a string of all values and write a line end
Console.WriteLine(string.Join("", a.Select(v => "-"))); // write the dashes

[Ideone]

like image 73
Patrick Hofman Avatar answered Dec 26 '22 09:12

Patrick Hofman