Solved

Q about Accessibility

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

895 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now