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!
===C#=== This example illustrates the [[C Sharp (programming language)|C#]] idea of [[Property (programming)#C#|properties]], which are a special type of [[Class (computer science)|class]] member. Unlike Java, no explicit methods are defined; a public 'property' contains the logic to handle the actions. Note use of the built-in (undeclared) variable <code>value</code>. <syntaxhighlight lang="csharp"> public class Student { private string name; /// <summary> /// Gets or sets student's name /// </summary> public string Name { get { return name; } set { name = value; } } } </syntaxhighlight> In later C# versions (.NET Framework 3.5 and above), this example may be abbreviated as follows, without declaring the private variable <code>name</code>. <syntaxhighlight lang="csharp"> public class Student { public string Name { get; set; } } </syntaxhighlight> Using the abbreviated syntax means that the underlying variable is no longer available from inside the class. As a result, the <code>set</code> portion of the property must be present for assignment. Access can be restricted with a <code>set</code>-specific access modifier. <syntaxhighlight lang="csharp"> public class Student { public string Name { get; private set; } } </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)