我在 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/