Solved

Q about Accessibility

Posted on 2007-04-04
4
196 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
  • 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

770 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