#611 – Accessibility of Members in a struct

Methods, field and properties within a struct can have one of three access modifiers, dictating the visibility of these members.

  • public – all code has access
  • private – only code within the struct has access
  • internal – code within the defining assembly has access
    public struct DogBark
    {
        public string BarkSound;
        public int BarkLength;

        // Constructor is public
        public DogBark(string barkSound, int barkLength)
        {
            BarkSound = barkSound;
            BarkLength = barkLength;
            hash = barkSound.GetHashCode();
        }

        // internal - accessible from code in the same assembly
        internal int GetHash()
        {
            return hash;
        }

        // private - accessible from code in this struct
        private int hash;
    }
Advertisements

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

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 )

Google+ photo

You are commenting using your Google+ 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 )

w

Connecting to %s

%d bloggers like this: