Inconsistent accessibility error with the following c# code. Why?

泪湿孤枕 提交于 2019-11-26 09:54:26

问题


Whats wrong with the following c# code? Compiler reports this error:

Inconsistent accessibility: parameter type \'ClassLibrary1.Interface1\' is less accessible than method \'ClassLibrary1.Class1.Class1(ClassLibrary1.Interface1)\'

with the following code:

interface Interface1<T>
{
    bool IsDataValid();
    /* Other interfaces */
}

public class Class1<T>
{
    public Interface1<T> interface1;

    public Class1(Interface1<T> interface1)
    {
        this.interface1 = interface1;
    }

}

I\'ve since designed my code differently using inheritence to but if anyone could tell me what the above is wrong I\'d greatly appreciate it.


回答1:


your "Interface1" isn't public..

public interface Interface1<T>
{
    bool IsDataValid();
    /* Other interfaces */
}



回答2:


Mark your interface as public:

public interface Interface1<T>

If you leave out the accessibility label, it defaults to internal, that is, only accessible to other classes within the assembly.




回答3:


second solution is If your interface is not public then dont make your class public where you are making a handle of interface.



来源:https://stackoverflow.com/questions/524761/inconsistent-accessibility-error-with-the-following-c-sharp-code-why

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!