Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Mutator method
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===D=== [[D (programming language)|D]] supports a getter and setter function syntax. In version 2 of the language getter and setter class/struct methods should have the <code>@property</code> attribute.<ref>{{cite web |url=http://dlang.org/function.html |title=Functions - D Programming Language |accessdate=2013-01-13}}</ref><ref>{{cite web|url=http://dlang.org/dstyle.html |title=The D Style |accessdate=2013-02-01}}</ref> <syntaxhighlight lang="d"> class Student { private char[] name_; // Getter @property char[] name() { return this.name_; } // Setter @property char[] name(char[] name_in) { return this.name_ = name_in; } } </syntaxhighlight> A <code>Student</code> instance can be used like this: <syntaxhighlight lang="d"> auto student = new Student; student.name = "David"; // same effect as student.name("David") auto student_name = student.name; // same effect as student.name() </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)