FILE_ID: 55 // DATE: 2023.01.19 C#的接口与抽象类 ```csharp using System.Collections; using System.Collections.Generic; using UnityEngine; public class Player : MonoBehaviour { MagicApprentice apprentice = new("Marisa"); public void Start() { apprentice.TellName(); apprentice.Ino(); } } interface IApprentice { public void TellName() { } } abstract class Magic { public abstract void Ino(); } //抽象类在接口之前继承 class MagicApprentice : Magic, IApprentice { private string name; public override void Ino() { Debug.Log("Master Spark!"); } public MagicApprentice(string name) { this.name = name; } public void TellName() { Debug.Log("I'm " + name); } } ``` 需要注意的一点放在注释了。 TAGS: C#