Solved

Q about Accessibility

Posted on 2007-04-04
4
194 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

12 Experts available now in Live!

Get 1:1 Help Now