[SOLVED] What does '=>' mean (in functions / property context)?

Issue

I got an auto generated code using Lambdas while developing a Xamarin application:

public override string this[int position] => throw new NotImplementedException();

public override int Count => throw new NotImplementedException();

What does the => operator mean in this context?

Thanks
R

Solution

These are not lambdas, they are Expression-bodied Members!

In the context of a property, these are basically the getters of a property simplified to become a single expression (as opposed to a whole statement).

This:

public override int Count => throw new NotImplementedException();

Is equivalent to:

public override int Count {
    get { throw new NotImplementedException(); }
}

Answered By – Sweeper

Answer Checked By – Marilyn (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published.