c# - 可访问性不一致 : parameter type for generic c# interface

标签 c#

我在 VisualStudio 中遇到以下错误

可访问性不一致:参数类型“mynamespace.ProgressChangedEvent”的可访问性低于方法“mynamespace.StartScreen.ReceiveUpdate(mynamespace.ProgressChangedEvent)”

我的界面是这样的

public interface IObserver<T>
{
     void ReceiveUpdate(T ev);
}

我的事件类看起来像这样

namespace mynamespace
{
//The event interface
interface Event {}

//Concrete Event
class ProgressChangedEvent : Event
{
    private int fileCount = 0;
    private int filesProcessed = 0;

    public ProgressChangedEvent(int fileCount, int filesProcessed)
    {
        this.fileCount = fileCount;
        this.filesProcessed = filesProcessed;
    }

    public int FileCount
    {
        get{return fileCount;}
        set{fileCount = value;}
    }

    public int FilesProcessed
    {
        get { return filesProcessed; }
        set { filesProcessed = value; }
    }


    }
}

类是一个表单,长这样

namespace mynamespace
{
  public partial class StartScreen : Form, IObserver<ProgressChangedEvent>
  {


   /*
    * Lots of form code...
    */

    #region IObserver<ProgressChangedEvent> Members

    public void ReceiveUpdate(ProgressChangedEvent ev)
    {
        throw new Exception("The method or operation is not implemented.");
    }

    #endregion
    }


}

ReceiveUpdate 方法被突出显示并显示上述错误。

最佳答案

你必须公开你的类(class):

class ProgressChangedEvent : Event
{

应该是

public class ProgressChangedEvent : Event
{

由于您的公共(public)方法 ReceiveUpdate() 需要一个类型为 ProgressChangedEvent 的变量,因此该类也必须是公共(public)的,以便它可以实际使用(从您的程序集外部) - 这就是您收到该错误的原因。

关于c# - 可访问性不一致 : parameter type for generic c# interface,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5320999/

相关文章:

c# - 改变字典的键

c# - BigInteger 解析八进制字符串?

c# - 如何在 C# 上创建网络 map ?

c# - 将双引号内联附加到字符串生成器时出现问题

c# - asp.net下拉列表向上打开

c# - 如何在RDLC中设置参数值

c# - Windows 10 中 UDP 的问题。UWP

c# - 我可以使用自己的扩展方法使对象为 null 吗?

c# - Asp.net Identity - 如何在不考虑鉴别器的情况下登录

javascript - 创建部分 View 以在索引页面中创建新内容