1

What is wrong with this code ?

public ScreenManager _ScreenManager
        {
            get { return screenManager; }
            internal set { screenManager = value; }
        }
        ScreenManager screenManager;

and I get this error:

Inconsistent accessibility: field type 'ScreenSystem.ScreenManager' is less accessible than field 'ScreenSystem.Screen.ScreenManager'
2
  • 6
    Worth noting: it's probably not a great idea to start the name of a public property with an underscore. Underscores are generally reserved for private fields (local variables). Commented Apr 25, 2012 at 19:46
  • Can you post some more code? It's kind of hard to get the full picture from what you've posted. Commented Apr 25, 2012 at 19:47

3 Answers 3

12

I'm going to assume the type ScreenManager is internal while the class containing your property is public.

The compiler is saying that a publicly-accessible field (ScreenSystem.Screen.ScreenManager) is of a type (ScreenSystem.ScreenManager) that isn't publicly-accessible.

Your field should generally be private anyway. And you might be missing a public in front of your class ScreenSystem.ScreenManager (it defaults to internal IIRC).

0
4

Here is your scenario:

namespace ScreenSystem
{
    internal class ScreenManager
    {
        public string Test { get; set; }
    }
}

namespace ScreenSystem
{
    public class Screen
    {
        public ScreenManager Manager
        {
            get; internal set;
        }
    }
}

Compiler Output
Inconsistent accessibility: property type 'ScreenSystem.ScreenManager' is less accessible than property 'ScreenSystem.Screen.Manager'

Here are the solutions, depending on what you're trying to do:

  • Make the Screen class internal
  • Make the ScreenManager class public
  • Make the ScreenManager class public and the Screen class internal
  • Make the Screen.Manager property internal (and remove the internal set accessor)

Either one of the above will compile without errors. It really just depends on what you're trying to achieve.

2
  • @RobertHarvey: What do you mean? Are you agreeing with my answer? Commented Apr 25, 2012 at 19:46
  • My guess is that ScreenSystem.Screen.ScreenManager is referring to class ScreenManager in namespace ScreenSystem.Screen and ScreenSystem.ScreenManager references the property ScreenManager in class ScreenManager (fully qualified to ScreenSystem.Screen.ScreenManager). There is only one class, therefore no namespace issue. It's just confusing because the class has the same name as the property.
    – Servy
    Commented Apr 25, 2012 at 19:56
2

It means that you have ScreenManager set up as private or protected yet you are are trying to make a property public that relies on ScreenManager. You can't do that.

Make ScreenManager public or make _ScreenManager the same accessibility as ScreenManager.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.