C# accessor - Accessors in c# - c# - c# tutorial - c# net
Accessor Methods - gets in c# :
- Because of encapsulation, those variables are generally private
- However, the outside world may need to use those variables
- The class implementor may choose to add a "get" method to return the value
- getName(), getAddress(), getPhone(), getBalance()
public class BankAccount {
private float balance;
public float getBalance()
{
return balance;
}
click below button to copy the code. By - c# tutorial - team
Accessor Methods - sets in c# :
- The class implementor may choose to implement a set method.
- The responsibility of the set method is to set the appropriate variable
- WHILST MAINTAINING data integrity of the object.
- setName(), setAddress(), setPhone(), setBalance()
public class BankAccount
{
private String ownerName;
public void setOwnerName(String aName)
{
ownerName = aName;
}
click below button to copy the code. By - c# tutorial - team



Accessor Methods - Indexers in c# :

