C# Hello world program – Your first program in C#
C# Hello world program – Your first program in C#
In this tutorial, we will discuss the concept of C# Hello world program
In this topic, we are going to learn how to write a simple Hollow world program in C#
What is the hello world program
The word “Hello world” cannot be forgotten by programmers as it is the first program learnt by programmers in every programming language.
“Hello world” program is very easy to learn and understand and the purpose of this program is to get us familiar with the basic requirements and syntax of this program in C# programming language
This program returns the simple output “Hello world” and is used to introduce programming languages to beginners.
Before you write a code in hello world program, you must ready your system for code writing, compilation and running.
Program 1
//Hollo world program in C# using System; public class HelloWorld //class name { public static void Main(string[] args)//main method { System.Console.WriteLine ("Hello World"); } }
When the above code is executed, it produces the following result
Hello World
Program 2
//Hello world program using System; namespace HelloWorld { class Hello { static void Main(string[] args) { String message="Hello World!"; System.Console.WriteLine(message); } } }
When the above code is executed, it produces the following result
Hello World!
A basic C# program consist the following parts
- A Name space declaration
- Class declaration & definition
- Class members declarations(Variables and class methods etc)
- main method (per-defined method)
- Statements or Expressions
Explanation of the program
//Hello world program
// symbol indicates the beginning of the comment in the C# program likes other program. comments (Commented lines) are not executes by the C# compiler(it is ignored by the compiler), they are used to programmers or developers to better understand the code
Namespace HelloWorld{…} – Here, The namespace is the keyword which is used to define our own Name space. in this program,we create a user defined namespace called HolloWorld
class Hello{…} – class is a object oriented programming technique and above statement use to create a class name – Hello
static void Main(string[] args){…} – The above statement is a main method of the class Hello. and the execution of every C# program start from the main() method. the pre-defined main methods is compulsory of the every C# program(object oriented programming technique)
System.Console.WriteLine (“Hello World”). – This is the piece of code used to prints Hello world in the screen. This is the output of the program
Important points of the C# program
- Every C# program must have a class definition (Object oriented programming)
- The execution of program begins from the main method(pre-defined method )
- The main method must be inside the class definition
Similar post
Hello world program in C language
Hello world program in C++ language