1

Looking through someone else's code I found this line of code:

     protected IDirectIp Iridium => _resolver.Resolve<IDirectIp>();

I was confused seeing a lambda (=>) instead of an equal sign (=). The dependency injection library is Unity, is this syntax specific to Unity?

Could anyone explain what this expression is doing?

Brian Ogden
  • 18,439
  • 10
  • 97
  • 176

3 Answers3

4

That's an expression bodied function. This was added in c# 6.0 and is equivalent to

protected IDirectIp Iridium
{
    get { return _resolver.Resolve<IDirectIp>(); }
}
dcastro
  • 66,540
  • 21
  • 145
  • 155
Chris
  • 4,393
  • 1
  • 27
  • 33
2

It's a shortcut added in C# 6.0 for defining the get body of a readonly property

https://github.com/dotnet/roslyn/wiki/New-Language-Features-in-C%23-6#expression-bodies-on-property-like-function-members

mdickin
  • 2,365
  • 21
  • 27
1

It is an expression bodied member from C# 6.0.

It is just shorthand for a property getter that returns everything after the =>.

DaveShaw
  • 52,123
  • 16
  • 112
  • 141