C# 类的方法介绍
在c#中,类的方法主要用来完成类或对象的行为。
方法的声明格式如下
[修饰符][返回类型]方法名
{
[方法体]
}
修饰符:分访问修饰符和声明修饰符

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace _004_类的方法
{internal class Program{static void Main(string[] args){TestMotoecycle moto = new TestMotoecycle();moto.StartEngine();//Protected修饰后的方法,不能在实例化的派生类中调用,只能在派生类内部调用//moto.AddGas(15);moto.Drive(5, 20);double speed = moto.GetTopSpeed();}public abstract class Motorcycle{public void StartEngine(){}protected void AddGas(int gallons){}public virtual int Drive(int miles,int speed){return 1;}public abstract double GetTopSpeed();}class TestMotoecycle:Motorcycle //继承{public override double GetTopSpeed(){return 108.4;}public void AddGasV(int X){AddGas(X);}}}
}