Finished Defining Property Getters & Setters
parent
d08a5442f5
commit
57944415e6
@ -38,4 +38,14 @@ A property is a member that provides a flexible mechanism to read, write, or com
|
||||
|
||||
```
|
||||
|
||||
Instead of a public data `Name`, we create a private data and public property member (with getter and setter)
|
||||
Instead of a public data `Name`, we create a private data and public property member (with getter and setter)
|
||||
|
||||
## Defining Property Getters and Setters
|
||||
|
||||
Reference:
|
||||
* [Auto-Implemented Properties (C# Programming Guide)](https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/auto-implemented-properties)
|
||||
* [How to implement a lightweight class with auto-implemented properties (C# Programming Guide)](https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/how-to-implement-a-lightweight-class-with-auto-implemented-properties)
|
||||
|
||||
Instead of implement property, it can be implemented automatically if it's standard getter & (or private) setter (as read-only object). Besides, we can declare setter to be private
|
||||
|
||||
Overall, property provide more concise and convenient way to define than field.
|
Loading…
x
Reference in New Issue
Block a user