namespace 接口
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
IWeapon my = new firegun();
hero mh = new hero();
mh.useweapon(my,this);
}
}
interface IWeapon //这里不写public就出错
{
void fight(Form1 f);
}
public class firegun : IWeapon
{
public void fight(Form1 f)
{
f.txt.AppendText("fu fu fu so hot!" + "\n");
}
}
public class hero
{
public void useweapon(IWeapon ss, Form1 f)
{
ss.fight(f);
}
}
}
```![图片说明](https://img-ask.csdn.net/upload/201912/18/1576656897_787775.png)