Visual Studio C# auto new lines
When writing lines to console, compiler automatically adds new lines, I mean:
using System;
class Hello
{
static void Main()
{
for ( int i = 0; i < 10; i++ )
{
Console.WriteLine("{0}", i);
bool bulas = i % 3 == 0;
if ( bulas )
{
开发者_Python百科Console.WriteLine("Boolas, {0}", bulas);
}
}
Console.ReadLine();
}
}
Output of this is:
0
Boolas, True
1
2
3
Boolas, True
4
5
6
Boolas, True
7
8
9
Boolas, True
What do I have to do if I want to have everything in one line?
Well, don't use Console.WriteLine
but Console.Write instead.
Console.WriteLine inserts a System.Environment.NewLine.
It is not the compiler who adds the new lines, but the WriteLine() method. WriteLine() writes whatever you pass plus a new line.
Use the Write() method instead to write stuff to the console without an extra new line.
精彩评论