Basic

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

C# 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 Java

Hello world program in C language

Hello world program in C++ language

Hello world program in Python

 

Write a Python program to print an integer
Calculate sum of two numbers - Example program in C#
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

1 month ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

2 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

10 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

10 months ago