2

Anyone can detail the error CS0053 error CS0053: Inconsistent accessibility: property type X is less accessible than property Y.

user496949
  • 83,087
  • 147
  • 309
  • 426
  • possible duplicate of ["Inconsistent accessibility" on class definition](http://stackoverflow.com/questions/3946095/inconsistent-accessibility-on-class-definition) – Caspar Kleijne Jan 30 '11 at 08:42

2 Answers2

6

Compiler error CS0053

A public construct must return a publicly accessible object. For more information

Here is an example from MSDN:

// CS0053.cs
class MyClass //defaults to private accessibility
// try the following line instead
// public class MyClass
{
}

public class MyClass2
{
   public MyClass myProperty   // CS0053
   {
      get
      {
         return new MyClass();
      }
      set
      {
      }
   }
}

public class MyClass3
{
   public static void Main()
   {
   }
}

In order to fix this, you nee to set MyClass as public, then it will have the same accessability as MyClass2.

Filip Ekberg
  • 36,033
  • 20
  • 126
  • 183
  • errr... so what's the point? i thought this message means `property A has setter & getter while property B has setter or getter only`... – shybovycha Jan 30 '11 at 08:33
  • @shybovycha, Well `MyClass2` wants to expose something that is "Less" accessable than itself hence `MyClass` is private and `MyClass2` tries to expose it as if it was `public` – Filip Ekberg Jan 30 '11 at 08:35
  • @Filip Ekberg, oh, i'm sorry. haven't seen no access attribute near MyClass for a few times =P – shybovycha Jan 30 '11 at 08:39
  • 3
    Wow; MSDN fail - top-level types default to internal, not private. – Marc Gravell Jan 30 '11 at 08:39
  • @Marc, not in c#? VB uses internal as default but not c# afaik? – Filip Ekberg Jan 30 '11 at 09:10
  • @Filip yes it does; `private` isn't even *legal* unless it is a nested type – Marc Gravell Jan 30 '11 at 09:17
  • @Filip: See [the documentation here](http://msdn.microsoft.com/en-us/library/ms173121.aspx). Specifically: "Classes and structs that are declared directly within a namespace...can be either public or internal. Internal is the default if no access modifier is specified." and "The access level for class members and struct members, including nested classes and structs, is private by default." VB.NET is different, and that's [explained here](http://msdn.microsoft.com/en-us/library/e8zxe4y5.aspx). – Cody Gray - on strike Jan 30 '11 at 09:24
  • Ah right, I mixed it up with properties which afaik are default: `private`, right? And in VB they're internal. Thanks @Code and @Marc for clearing that up. – Filip Ekberg Jan 30 '11 at 09:49
0

have a look on http://msdn.microsoft.com/en-us/library/532wtsbc.aspx

// CS0053.cs
class MyClass
// try the following line instead
// public class MyClass
{
}

    public class MyClass2
    {
       public MyClass MyProperty   // CS0053
       {
          get
          {
             return new MyClass();
          }
          set
          {
          }
       }
    }

    public class MyClass3
    {
       public static void Main()
       {
       }
    }

Note: if you have any doubt in compiler error you can search

http://msdn.microsoft.com/en-us/library/5feh24w0.aspx

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
anishMarokey
  • 11,279
  • 2
  • 34
  • 47