我在VisualStudio中收到以下错误
可访问性不一致:参数类型'mynamespace.ProgressChangedEvent'的访问方式不如方法'mynamespace.StartScreen.ReceiveUpdate(mynamespace.ProgressChangedEvent)'
我的界面看起来像这样
public interface IObserver<T>
{
void ReceiveUpdate(T ev);
}
My Events类看起来像这样
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 ,并显示上述错误。
答案 0 :(得分:6)
你必须公开你的课程:
class ProgressChangedEvent : Event
{
应该是
public class ProgressChangedEvent : Event
{
由于您的公共方法ReceiveUpdate()
期望变量类型为ProgressChangedEvent
,因此该类必须也是公共的,以便实际可以使用它(从程序集外部) - 这就是您收到该错误的原因。
答案 1 :(得分:1)
您需要公开ProgressChangedEvent
课程。