When you implement a property in a class, you can specify different access modifiers for the get vs. set accessors. This is true whether you are implementing the property yourself, or using an automatic property.
Different combinations of access modifiers include:
- get/set both public – client can read/write property value
- get/set both private – client has no access to the property
- get public, set private – property is read-only
- get private, set public – property is write-only
1
2
3
4
5
6
7
8
9
10
11
| // get/set both publicpublic string Name { get; set; }// get/set both privateprivate string SecretName { get; set; }// public get => read-onlypublic string CalcName { get; private set; }// public set => write-onlypublic string WriteOnlyName { private get; set; } |

