C# - What is the difference between Console.Write and Console.WriteLine Methods in C Sharp

Scenario: Download Script

You are working as C# developer and writing Console Application. You need to display some lines and variables values to Console.

You can use Console.Write( ) or Console.WriteLine() functions.

Console.Write() method will write the values to the screen without adding new line character, that means if you try to print anything, it will start from the same line.

Console.WriteLine() method will write the values to screen also also include new line character. That means if you write another after that it will start from next line.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _04_Console_Screen_Disappear_Immediately
{
    class Program
    {
        static void Main(string[] args)
        {
            string testvariable = "This is string variable";
            //Display string
            Console.Write("This is first Line ");
            Console.WriteLine("2nd Line Welcome to TechBrothersIT.com");
            //display variable variable
            Console.Write(testvariable);
            //wait for input
            Console.ReadLine();
        }
    }
}

Diffrence between Write and WriteLine Methods in C#

1 comment:

  1. The difference between Console.Write and Console.WriteLine is actually quite a lot. They are inherently very different. geometry dash deadlocked you can go here to learn more about this issue.

    ReplyDelete