Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

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.

like image 341
Crippeoblade Avatar asked Feb 07 '09 23:02

Crippeoblade


3 Answers

your "Interface1" isn't public..

public interface Interface1<T>
{
    bool IsDataValid();
    /* Other interfaces */
}
like image 141
Sciolist Avatar answered Nov 05 '22 21:11

Sciolist


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.

like image 42
Eric King Avatar answered Nov 05 '22 20:11

Eric King


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

like image 1
vijay Avatar answered Nov 05 '22 21:11

vijay