Answers for "get and set unity"

C#
3

get and set unity

class Thing {
  private int secret; // This is a field.

  public int Secret { // This is a property.
    get {
      Debug.Print("Somebody is accessing the secret!");
      return secret;
    }

    set {
      Debug.Print("Somebody is writing to the secret!");
      secret = value; // Note the use of the implicit variable "value" here.
    }
  }
}
Posted by: Guest on November-04-2020

C# Answers by Framework

Browse Popular Code Answers by Language