Let’s write Hello World program using C#

OK, now that you have Visual Studio installed and also created a console application project lets write our first C# program that will print the world famous “Hello World” string on the black console window.

Console.Write function

If you are familiar with C programming language then you might know that we use the printf function to print any text on the console window using C language. If you are familiar with C++ then you might know that we use the cout function to print any text on the console window using C++. Similarly in C# we use the Console.Write function. Here Console is the class which has a static function called Write. You will learn about static in coming tutorials. Right now all you should understand is that whenever you need to print any text on the black console window just use the Console.Write function. Look at the code below

class Program  {          static void Main(string[] args)          {              Console.Write("Hello World !");          }  }

See how we have written the Console.Write(“Hello World !”) line inside the Main function. Also notice that there is a semicolon ( ; ) at the end of this line. In C# you put a semicolon to mark the end of the statement.

Compile the program

Right click on your project and click Build

Build console application
This will compile your code. If you have not made any mistake in writing your code then you should see the message ‘Build Succeeded’ at the bottom left corner of Visual Studio.

Run the program

Now let’s run the program and see the output. To run your code either press Ctrl + F5 from your keyboard or click on Debug -> Start without debugging option from the top menu

Run console application
This will run your program and show you the output on the console window like this

Output - Hellow world console application
See that Hello World is printed in the first line.

Quick Links



Total Followers
Study Group Created
Study Group Joined
Following Teacher
Following Organization
Blog Articles Added
Questions Asked
Questions Answered
Jobs Posted
Total Members in Group
Questions asked by members
Tasks added in this Group

Please wait..


Login to Open ESchool OR Create your account    Login   SignUp