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);
}
}
}
```
接口的默认修饰是public
说的是接口中定义的方法是public,而不是说接口本身是public
public class firegun : IWeapon
你这里firegun有public,而IWeapon没有。要么这里去掉,要么IWeapon加上
https://www.cnblogs.com/lizhenlin/p/6773385.html
类的默认修饰是internal