mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 17:41:41 +00:00
Added properties (get and set)
This commit is contained in:
parent
81f58f4b0d
commit
fe5001ca96
@ -240,7 +240,7 @@ enum HouseSize { // An example of an enum
|
||||
|
||||
class Message : GLib.Object { // Class Message extends GLib's Object
|
||||
private string sender; // a private field
|
||||
public string text {get; set;} // a public property
|
||||
public string text {get; set;} // a public property (more on that later)
|
||||
protected bool is_digital = true; // protected (this class and subclasses)
|
||||
internal bool sent = false; // internal (classes in same package)
|
||||
|
||||
@ -302,6 +302,24 @@ public class SignalDemo : GLib.Object {
|
||||
// You may use the connect() method and attach as many handlers as you'd like.
|
||||
// They'll all run when the signal is emitted.
|
||||
|
||||
// Properties (getters and setters)
|
||||
|
||||
class Animal : GLib.Object {
|
||||
private int _legs; // prefixed with underscore to prevents name clashes
|
||||
|
||||
public int legs {
|
||||
get { return _legs; }
|
||||
set { _legs = value; }
|
||||
}
|
||||
|
||||
public int eyes { get; set; default = 5; } // Shorter way
|
||||
}
|
||||
|
||||
rabbit = new Animal();
|
||||
rabbit.legs = 2;
|
||||
rabbit.legs += 2;
|
||||
rabbit.eyes = 2;
|
||||
|
||||
```
|
||||
* More Vala documentation can be found [here](https://valadoc.org/).
|
||||
* Read about building GUIs with GTK+ and Vala [here](http://archive.is/7C7bw).
|
||||
|
Loading…
Reference in New Issue
Block a user