C# main方法示例

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();

        }

    }

}
C#中的Main方法

在C# 编程中,程序只有一个main方法。main方法是程序的入口点,程序从这里开始执行。
C#中,Main方法可以返回void或者int类型。必须在类或者结构中使用静态修改器声明。
Main方法可以不带参数声明,也可以带参数声明。

日期:2020-04-11 23:03:45 来源:oir作者:oir