Solved

Q about Accessibility

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

820 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