![](/img/trans.png)
[英]How to solve the Error: Inconsistent accessibility: parameter type for generic c# interface?
[英]Inconsistent accessibility: parameter type for generic c# interface
我在Visual Studio中遇到以下错误
可访问性不一致:与方法“ mynamespace.StartScreen.ReceiveUpdate(mynamespace.ProgressChangedEvent)”相比,参数类型“ 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 ProgressChangedEvent : Event
{
应该
public class ProgressChangedEvent : Event
{
由于您的公共方法ReceiveUpdate()
期望一个类型为ProgressChangedEvent
的变量,因此该类也必须是公共的,这样它才可以实际使用(在程序集外部)-这就是为什么会出现该错误的原因。
您需要公开您的ProgressChangedEvent
类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.