lostfalling 2019-12-18 16:14 采纳率: 44.4%
浏览 599
已采纳

c# 不是说接口的默认修饰是public ,接口不写public就报错了“可访问性不一致”,这是什么情况?

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)
  • 写回答

2条回答 默认 最新

  • threenewbee 2019-12-18 16:25
    关注

    接口的默认修饰是public
    说的是接口中定义的方法是public,而不是说接口本身是public

    public class firegun : IWeapon
    你这里firegun有public,而IWeapon没有。要么这里去掉,要么IWeapon加上

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?