Skip to content

Commit

Permalink
update to included expression bodied getters and setters (dotnet#2008)
Browse files Browse the repository at this point in the history
Customer reported issue with  C# 7 being released, this new syntax was
not discussed.
  • Loading branch information
BillWagner authored Apr 25, 2017
1 parent 1413bca commit f9eab74
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions docs/csharp/properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,25 @@ public class Person
}
```

When a property implementation is a single expression, you can
use *expression bodied members* for the getter or setter:

```csharp
public class Person
{
public string FirstName
{
get => firstName;
set => firstName = value;
}
private string firstName;
// remaining implementation removed from listing
}
```

This simplified syntax will be used where applicable throughout this
topic.

The property definition shown above is a read-write property. Notice
the keyword `value` in the set accessor. The `set` accessor always has
a single parameter named `value`. The `get` accessor must return a value
Expand Down Expand Up @@ -114,7 +133,7 @@ public class Person
{
public string FirstName
{
get { return firstName; }
get => firstName;
set
{
if (string.IsNullOrWhiteSpace(value))
Expand Down Expand Up @@ -276,7 +295,7 @@ public class Person
private string firstName;
public string FirstName
{
get { return firstName; }
get => firstName;
set
{
firstName = value;
Expand All @@ -287,7 +306,7 @@ public class Person
private string lastName;
public string LastName
{
get { return lastName; }
get => lastName;
set
{
lastName = value;
Expand Down Expand Up @@ -331,7 +350,7 @@ public class Person : INotifyPropertyChanged
{
public string FirstName
{
get { return firstName; }
get => firstName;
set
{
if (string.IsNullOrWhiteSpace(value))
Expand Down

0 comments on commit f9eab74

Please sign in to comment.