[英]Inconsistent accessibility: parameter type for generic c# interface
I am getting the following error in VisualStudio 我在Visual Studio中遇到以下错误
Inconsistent accessibility: parameter type 'mynamespace.ProgressChangedEvent' is less accessible than method 'mynamespace.StartScreen.ReceiveUpdate(mynamespace.ProgressChangedEvent)' 可访问性不一致:与方法“ mynamespace.StartScreen.ReceiveUpdate(mynamespace.ProgressChangedEvent)”相比,参数类型“ mynamespace.ProgressChangedEvent”的访问性较差
My interface looks like this 我的界面看起来像这样
public interface IObserver<T>
{
void ReceiveUpdate(T ev);
}
My Events class looks like this 我的活动课看起来像这样
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. 方法ReceiveUpdate突出显示,并显示上述错误。
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. 由于您的公共方法
ReceiveUpdate()
期望一个类型为ProgressChangedEvent
的变量,因此该类也必须是公共的,这样它才可以实际使用(在程序集外部)-这就是为什么会出现该错误的原因。
您需要公开您的ProgressChangedEvent
类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.