Solved

Q about Accessibility

Posted on 2007-04-04
4
199 Views
Last Modified: 2010-04-15
Hello,

perhaps a dumb questioni but I am curious as to why I am not getting a "Inconsistent Accessibility" error or at least a warning.  For example, if I had a class like the following:

internal class Person
{
    //properties
    public string FirstName
   {
         get { ............. }
         set { ............ }
   }
}

My property has a greater accessibility level than my class declaration.  I am surprised that it compiles w/o an error or warning.

thanks
0
Comment
Question by:brdrok
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
Nico earned 125 total points
ID: 18851005
Internal means that the class is public within the assembly that it is declared in. So I suppose that means that a public property of an internal class is public for only this assembly too.

on http://msdn2.microsoft.com/en-us/library/wxh6fsc7.aspx you can find more info.
0
 
LVL 3

Expert Comment

by:Nico
ID: 18851083
Also it might be helpful to read chapter 3.5 of the C# language specification, which describes exactly how this stuff works :)
0
 
LVL 25

Assisted Solution

by:dstanley9
dstanley9 earned 125 total points
ID: 18851347
That is correct.  Public properties of an internal class will be available to all classes within that assembly.  Private methods of an internal class are still only available to that class.  Proetected methods of an internal class are available to inherited classes within that assembly (since it's internal you can't inherit from it in another assembly).

So there's nothing "inconsistent" about defining a public property on an internal class - it will still only be available within the assembly.
0
 
LVL 7

Author Comment

by:brdrok
ID: 18853391
thanks for the comments.  I was thinking it's odd that public properties is legal even though the class has been declared as internal.  But it has to be that way if for no other reason that should an internal class implement some kind of interface it wouldn't be able to if an internal class couldn't expose any public members, methods, etc.
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

622 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question