Brent Arias
Brent Arias

Reputation: 30155

How to Coalesce a Lambda Delegate

I want to do this:

class Foo {

  static Func<string> sRunner;

  Func<string> _runner;

  public Foo(Func<string> runner){

    _runner = runner ?? sRunner ?? () => "Hey!";

  }
}

I get an "invalid expression" term on the lambda. Can that be fixed inline?

Upvotes: 5

Views: 903

Answers (1)

Yuriy Faktorovich
Yuriy Faktorovich

Reputation: 68667

_runner = runner ?? sRunner ?? (() => "Hey!");

Upvotes: 12

Related Questions