#714 – Accessibility of a Public Method in an Internal Type

When you declare a class with an accessibility of internal, the class is usable only from code within the same assembly.  If this class then contains a member whose accessibility is public, that member is still limited to an accessibility level of internal.  A member of a class cannot be more accessible than the class itself.

This makes sense.  If we have code that doesn’t know about about a DogCollar class, it certainly can’t invoke the ReportSize method of the DogCollar class.

    // Can only use DogCollar within this assembly
    internal class DogCollar
        // Marked as public, but effectively internal
        public double Size { get; set; }

        public DogCollar(double size)
            Size = size;

        // Also effectively internal
        public void ReportSize()
            Console.WriteLine(string.Format("Collar is {0} in long", Size));

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

2 Responses to #714 – Accessibility of a Public Method in an Internal Type

  1. in fact internal makes no sense 😀

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: