#321 – Accessibility of Constants

As with other class members, you can apply access modifiers to constants defined in a class to define their accessibility.  Accessibility dictates what other code has access to the constant’s value.

  • public – All code has access
  • private – Only code in the defining class has access
  • protected – Code in the defining class or derived classes has access
  • internal – All code in the defining assembly has access
  • protected internal – Code in the defining assembly or in derived classes has access
        // All code has access
        public const string PluralOfDog = "Dogs";

        // Only this class has access
        private const Breeds DefaultBreed = Breeds.Retriever;

        // Subclass has access
        protected const string DefaultDogName = "Bowser";

        // Code in same assembly has access
        internal const string TargetArchitecture = "x86";

        // Code in same assembly or subclass has access
        protected internal const int DeckSize = 52;
Advertisements

About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

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

%d bloggers like this: