Say Hello

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.

Before starting this project I assume that everyone have a basic knowledge of Microsoft Visual Studio and creating Console applications in Visual Studio. If not read it here how to create Console Applications using MS Visual Studio.

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!");
        }
    }
}

If you didn't get the other parts of the code read it here Introduction to C#.

Run it and happy coding ;)
Any doubt or suggestion write here. I will try my best to help. Before posting your code you must escape it to view. To format your source code and use format highlighting, post your source code inside
< code >< pre > -- Your source code -- < /pre >< /code > (Remove spaces from pre and code tags).

No comments:

Post a Comment