views:

85

answers:

8

Hi, 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 )
            {
                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?

+10  A: 

Well, don't use Console.WriteLine but Console.Write instead. :)

Tamás Szelei
LOL! When I think about it, it looks so stupid... And I've been writing Write and WriteLns in pascal for about two years and it didn't come to my head... Thanks!
bah
You're welcome :)
Tamás Szelei
+1  A: 

Use Console.Write instead of Console.WriteLine

JaredPar
@Downvoter, care to explain?
JaredPar
+1  A: 

You can use Console.Write() instead of Console.WriteLine().

Harry Steinhilber
+1  A: 

Use Console.Write

jasonh
+1  A: 

Use Console.Write instead.

Femaref
+2  A: 

Console.Write, http://msdn.microsoft.com/en-us/library/hebffx2d.aspx

Wallstreet Programmer
+4  A: 

I'll add my [identical] answer to the mix:

You're not using the Write method. (That pun kills me!)

Console.Write() is what you should use. WriteLine also writes the Carriage Return and LineFeed.

Atømix
+1, just because of the pun.
jdmichal
Well, with a relatively easy question like this ( that you know is going to elicit 50 responses ) you just gotta have a bit of fun with it. Mind you, one person doesn't appreciate it ( or didn't get it )
Atømix
Haha, this should be voted highest, not mine :)
Tamás Szelei
+1  A: 

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.

CesarGon
To be fair... in the end, it's the compiler that reads `writeline` and writes the IL that does a carriage return, but I know what you mean.
Atømix
/me rolls his eyes.
CesarGon