C#的接口与抽象类

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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);
}
}

需要注意的一点放在注释了。