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.
精彩评论