开发者

Inconsistent accessibility: parameter type for generic c# interface

I am getting the following error in VisualStudio

Inconsistent accessibility: parameter type 'mynamespace.ProgressChangedEvent' is less accessible than method 'mynamespace.StartScreen.ReceiveUpdate(mynamespace.ProgressChangedEvent)'

My interface looks like this

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

My Events class looks like this

开发者_StackOverflow中文版
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; }
    }


    }
}

The class is a form, it looks like this

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
    }


}

The method ReceiveUpdate is highlighted and the above error is shown.


You have to make your class public:

class ProgressChangedEvent : Event
{

should be

public class ProgressChangedEvent : Event
{

Since your public method ReceiveUpdate() is expecting a variable of type ProgressChangedEvent, that class must be public too so it can actually be used (from outside your assembly) - that's why you get that error.


You need to make your ProgressChangedEvent class public.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜