473,626 Members | 3,265 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

inconsistent accessibility error

Consider the following code fragment

public class Wrapper {
protected enum E { IN, OUT };
public class C {
protected void foo(E e) { }
}
}

I want the class C to be accessible from outside the wrapper class, but not
the method foo. Compiling this gives the error:

Inconsistent accessibility: parameter type Wrapper.E' is less accessible
than method Wrapper.C.foo

but the accessibility of both types is "protected"
Nov 25 '05 #1
5 27246
C can't see E simply because E does not subclass C - it is *embedded* in it;
protected items are only available to sub-classes.

Possible fixes:
Move E to inside C
Make E public - it is only an enum after all
(possibly something involving making E internal protected and C internal,
but that has it's own limitations)

Hope that helps,

Marc

"Andy Fish" <aj****@blueyon der.co.uk> wrote in message
news:ON******** ******@TK2MSFTN GP10.phx.gbl...
Consider the following code fragment

public class Wrapper {
protected enum E { IN, OUT };
public class C {
protected void foo(E e) { }
}
}

I want the class C to be accessible from outside the wrapper class, but
not the method foo. Compiling this gives the error:

Inconsistent accessibility: parameter type Wrapper.E' is less accessible
than method Wrapper.C.foo

but the accessibility of both types is "protected"

Nov 25 '05 #2
Sorry - I mean't:
C can't see E simply because C does not subclass
Wrapper, and E is defined (protected) in Wrapper

Marc

"Marc Gravell" <mg******@rm.co m> wrote in message
news:e3******** ******@TK2MSFTN GP14.phx.gbl...
C can't see E simply because E does not subclass C - it is *embedded* in
it; protected items are only available to sub-classes.

Possible fixes:
Move E to inside C
Make E public - it is only an enum after all
(possibly something involving making E internal protected and C internal,
but that has it's own limitations)

Hope that helps,

Marc

"Andy Fish" <aj****@blueyon der.co.uk> wrote in message
news:ON******** ******@TK2MSFTN GP10.phx.gbl...
Consider the following code fragment

public class Wrapper {
protected enum E { IN, OUT };
public class C {
protected void foo(E e) { }
}
}

I want the class C to be accessible from outside the wrapper class, but
not the method foo. Compiling this gives the error:

Inconsistent accessibility: parameter type Wrapper.E' is less accessible
than method Wrapper.C.foo

but the accessibility of both types is "protected"


Nov 25 '05 #3
Andy Fish <aj****@blueyon der.co.uk> wrote:
Consider the following code fragment

public class Wrapper {
protected enum E { IN, OUT };
public class C {
protected void foo(E e) { }
}
}

I want the class C to be accessible from outside the wrapper class, but not
the method foo. Compiling this gives the error:

Inconsistent accessibility: parameter type Wrapper.E' is less accessible
than method Wrapper.C.foo

but the accessibility of both types is "protected"


Consider the following:

public class Subclass extends C
{
public void Something()
{
foo(????);
}
}

foo is accessible here, but E isn't. Hence the error.

Does foo definitely need to be protected rather than private?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 25 '05 #4
Marc Gravell <mg******@rm.co m> wrote:
Sorry - I mean't:
C can't see E simply because C does not subclass
Wrapper, and E is defined (protected) in Wrapper


No, C can definitely see E due to being nested within T. See section
10.5.2 of the spec (ECMA numbering):

<quote>
The accessibility domain of a nested member M declared in a type T
within a program P, is defined as follows (noting that M itself may
possibly be a type):

[...]
If the declared accessibility of M is protected, let D be the union of
the program text of T and the program text of any type derived from T.
</quote>

Now, in our case, C is within the program text of Wrapper, so it has
access to E.

The problem is that things which may logically be able to call foo (by
deriving from C) wouldn't have access to E.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 25 '05 #5
Fair enough! Learn something new every day...

;-p

Marc

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Marc Gravell <mg******@rm.co m> wrote:
Sorry - I mean't:
C can't see E simply because C does not subclass
Wrapper, and E is defined (protected) in Wrapper


No, C can definitely see E due to being nested within T. See section
10.5.2 of the spec (ECMA numbering):

<quote>
The accessibility domain of a nested member M declared in a type T
within a program P, is defined as follows (noting that M itself may
possibly be a type):

[...]
If the declared accessibility of M is protected, let D be the union of
the program text of T and the program text of any type derived from T.
</quote>

Now, in our case, C is within the program text of Wrapper, so it has
access to E.

The problem is that things which may logically be able to call foo (by
deriving from C) wouldn't have access to E.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Nov 28 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4149
by: Ryan | last post by:
I get an error every so often with a DTS package on SQL 7. Error as follows. The connection is currently being used by a task. The connection cannot be closed or re-used. This doesn't happen all the time and I can sometimes (more often than not) get the DTS package to complete in it's entirety.
4
2553
by: Steven Quail | last post by:
Hi to all, I am trying to get the hang of using interfaces and for some reason I am getting the "inconsistent accessibility where property ... is less accessible than property ...(cs0052)". What I have is the following: (sorry if the syntax is incorrec)
1
68018
by: Sunit Joshi | last post by:
I get this message "Inconsistent accessibility: return type 'TimeTracker.TrackerObjects.Project' is less accessible than method 'TimeTracker.TrackerObjects.GetProject(int)'" Here's the code namespace TimeTracker { public class TrackerObjects { private static Project aProject=null;
3
37064
by: AAV | last post by:
what is wrong with the code i get 'Error 1 Inconsistent accessibility: parameter type 'ConsoleApplication1.Garage.CarDelegate' is less accessible than method 'ConsoleApplication1.Car.process(ConsoleApplication1.Garage.CarDelegate) ' E:\VS2005_Study\Delegates.cs 49 23 ConsoleApplication1 ' using System;
0
991
by: mariano774 | last post by:
Hello, I'm building a POC architecture framework, in which I have my business objects (BOs) made of internal classes and my transfer objects (TOs) made of public classes. what I'd like to do is have a constructor for each TO and use the BO as a parameter, so to build the TO using the BO what I coded is this public class ClientTO { public string name; public ClientTO (ClientBO client) {
3
4411
by: WillyL | last post by:
I keep getting the following error message: Inconsistent accessibility: return type 'System.Collections.Generic.IEnumerable<Iteraties.Aandeel>' is less accessible than method 'Iteraties.AandeelPortefeuille.GetEnumerator()' I have the following code: using System; using System.Collections; using System.Collections.Generic;
1
3227
by: bachyen | last post by:
I have the following code, but it is error when I build it. Can you help me? Can you tell me more about 'Inconsistent accessibility: return type', 'Inconsistent accessibility: parameter type'. using System; public class Tinh_khoang_cach_Ham_tu_dinh_nghia { struct DIEM { public Double x;
3
3220
by: EvilProject | last post by:
While working on a scripting engine I Encountered the following problem. First I Created an abstract base class EPType that represent a variable type in the script. internal abstract class EPType { private String m_Name; public String Name { get { return m_Name; } }
9
5154
by: dylan.miller | last post by:
I'm having trouble understanding the internal access modifier. There are many classes in my assembly that should not be accessible outside of the assembly. I've used the internal access modifier for these classes. I have public classes that use the internal classes, but I get a CS0051 error if I use an internal class as a parameter to a protected function of a public class. For example: internal class InternalClass { }
0
8265
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8196
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8705
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6125
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4197
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2625
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1808
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1511
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.