0

What does the following mean when written in a subclass:

public override bool IsReadOnly
    => false;

Does this differ from:

public override bool IsReadonly
{
  get 
  {
    return false;
  }
}
steve_cdi
  • 166
  • 6

2 Answers2

2

What does the following mean when written in a subclass

This is a new feature in C# 6.0 called Expression Body, this is a syntactic sugar that allows define getter-only properties and indexers where the body of the getter is given by the expression body.

Does this differ from

No, there is no difference between this and the classic form, is just an syntactic sugar.

Methods as well can be defined as an expression-bodied:

public void PrintLine(string line) => Console.WriteLine(line);
Arturo Menchaca
  • 15,783
  • 1
  • 29
  • 53
1

Its the same thing, there is no difference, like our friend Slaks said, its just syntactic sugar. "=>" is the lambda expression of assignment.