From the early days since I started programming, every language I learnt and every first class I attended was of saying hello to the world. And I think it has been a tradition to start the first day with programming with Hello World! Hence not breaking the tradition let’s begin with a Hello World program.
Know it:
For printing any message or String value on the console we can use two simple and similar looking methods.
Console.Write()
Console.WriteLine()
I think the difference between both methods are pretty much clear to everyone reading this, if not read it below.
Console.Write()
Prints the String value. Or simply used to print any message or value on Console.
Read more at
msdn.
Console.WriteLine()
Similar as
Console.Write() but after printing it advances the current cursor position to next line. Which is pretty much equivalent to
printf(“string-value \n”) in C and
cout<<”string-value”<<endl in C++. Read more at
msdn.
Let’s implement:
Since any program begins from the main function. Let’s navigate to the main function and add a line that will print our message.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
Run it and happy coding ;)
Labels: .NET, Basic, C#