#611 – Accessibility of Members in a struct
June 22, 2012 Leave a comment
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; }