mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 09:41:36 +00:00
Added example of C# inline properties (#1464)
This was a really cool & useful trick/feature that I found while learning C#.
This commit is contained in:
parent
819d16b7e5
commit
d48aef96f1
@ -671,6 +671,10 @@ on a new line! ""Wow!"", the masses cried";
|
|||||||
int _speed; // Everything is private by default: Only accessible from within this class.
|
int _speed; // Everything is private by default: Only accessible from within this class.
|
||||||
// can also use keyword private
|
// can also use keyword private
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
// Properties also have a special syntax for when you want a readonly property
|
||||||
|
// that simply returns the result of an expression
|
||||||
|
public string LongName => Name + " " + _speed + " speed";
|
||||||
|
|
||||||
// Enum is a value type that consists of a set of named constants
|
// Enum is a value type that consists of a set of named constants
|
||||||
// It is really just mapping a name to a value (an int, unless specified otherwise).
|
// It is really just mapping a name to a value (an int, unless specified otherwise).
|
||||||
|
Loading…
Reference in New Issue
Block a user