Main method in C#

In this article I will explain the concept of Main method in C#.
  • 2104

Introduction

In C# programming the program have only one main method. The Main method is the entry point of our program, where the program starts execution. The Main method can be void or int return type in C#. It must be declared with static modifier inside a class or struct. The Main method can be declared without parameters or with parameters.

Example

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace Main_Method

{

    class checkMetho

    {

        float num, percent;

        public void accept()

        {

            Console.Write("\nEnter your marks. (Total Mark = 850):\t");

            num = float.Parse(Console.ReadLine());

        }

        public void print()

        {

            percent = (float)num / 850 * 100;

            if (percent < 35)

            {

                Console.WriteLine("Sorry!!! You are fail.your marks is " + percent);

            }

            else if (percent > 35 && percent < 50)

            {

                Console.WriteLine("You got grade D and your percentage marks is " + percent);

            }

            else if (percent > 50 && percent < 60)

            {

                Console.WriteLine("You got grade C and you percentage marks is " + percent);

            }

            else if (percent > 60 && percent < 75)

            {

                Console.WriteLine("You got grade B and you percentage marks is " + percent);

            }

            else

            {

                Console.WriteLine("You got grade A and your percentage marks is " + percent);

            }

        }

    }

   class Program

    {

        static void Main(string[] args)

        {

            // Starting execution

            // Creating object of class check

            checkMetho ma = new checkMetho();

            ma.accept(); //Invoking accept method

            ma.print(); //Invoking print method

            Console.ReadLine();

        }

    }

}

 

Output 

 Clipboard175.jpg

© 2020 DotNetHeaven. All rights reserved.