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

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

1 day ago

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago