Search code examples
c#parametersenums

Inconsistent accessibility when using enum as parameter


So I'm making a small program, but ran into a problem. I'm trying to open a (WPF) form using an enum as parameter, as you can see in the code snippet below.

public myForm(otherClass.myEnum en)
{
    InitializeComponent();
    //my other code comes here
}

And in otherClass:

class otherClass
{
    public enum myEnum
    {
        item1,
        item2
    }
}

Now, my problem is that Visual Studio is giving me the following error:

Error   1   Inconsistent accessibility: parameter type 'myProject.otherClass.myEnum' is less accessible than method 'myProject.myForm.myForm(myProject.otherClass.myEnum)'  C:\Users\MyUsername\Documents\Visual Studio 2013\Projects\MyProject\MyProject\myForm.xaml.cs    46  16  myForm

However, the enum is public. I looked up the error, but other people usually forgot to make their enum public, and I did make mine public. I also prefer not to move the enum to my form class.

All help is appreciated!


Solution

  • The accessibility of a type is restricted by it's most outer scoping type accessibility, in our case for the enum it will be the internal because it's scoped inside the definition of the other class and classes by default are defined as internal. The issue might arise if your form is defined as public and one of it's public members , in our example the public constructor accepts an internal accessibility type argument. To fix the issue you can define the other class as public.