Posted by: Cirilo Meggiolaro | 01/29/2009

Tip of the day #107 – Internal members

Internal members are that types or member types accessible only within an assembly.

The use of internal members is recommended when you want to hide types or type members from other parts of an application like components with objects that must be available to the whole assembly but not outside it such as UI for example.

How to…

The implementation is pretty straightforward:

The following code defines a class that is accessible to all classes within the assembly but not outside it:

internal class Calculator
{
    /// Accessible only within the assembly.
}

The next code defines a public class and an internal method that is accessible within the assembly only:

/// The class is accessible from outside the assembly.
public class Calculator
{
    internal decimal ResolveEquation(string expression)
    {
        /// The method is accessible by all classes within
        /// the same assembly but not outside it.

        return 0;
    }
}

Advertisements

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 )

Google+ photo

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

Connecting to %s

Categories

%d bloggers like this: