我在VisualStudio中收到以下错误
可访问性不一致:参数类型'mynamespace.ProgressChangedEvent'比方法'mynamespace.StartScreen.ReceiveUpdate(mynamespace.ProgressChangedEvent)'更难访问
我的界面看起来像这样
public interface IObserver<T>
{
void ReceiveUpdate(T ev);
}
Run Code Online (Sandbox Code Playgroud)
我的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; }
}
}
}
Run Code Online (Sandbox Code Playgroud)
这个类是一个表单,它看起来像这样
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
}
}
Run Code Online (Sandbox Code Playgroud)
突出显示ReceiveUpdate方法,并显示上述错误.
你必须公开你的课程:
class ProgressChangedEvent : Event
{
Run Code Online (Sandbox Code Playgroud)
应该
public class ProgressChangedEvent : Event
{
Run Code Online (Sandbox Code Playgroud)
由于您的公共方法ReceiveUpdate()需要一个类型的变量ProgressChangedEvent,因此该类必须是公共的,因此它实际上可以被使用(来自程序集外部) - 这就是您得到该错误的原因.