Search code examples
c#functionlambdaoperatorsexpression-body

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


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(); }
    }