What does the highlighted line do?

public class Presenter { private readonly IView _view; private readonly IService _service; public Presenter(IView view, IService service) { _view = view; _service = service; _view.UserIdChanged += () => UpdateUserInfo(); // <<<<<< } private void UpdateUserInfo() { var user = _service.GetUser(_view.UserId); _view.Username = user.Username; _view.Age = user.Age; } } 

Closed due to the fact that off-topic by user194374, aleksandr barakin , rdorn , Alex , Denis Bubnov on Dec 14 '16 at 11:05 .

  • Most likely, this question does not correspond to the subject of Stack Overflow in Russian, according to the rules described in the certificate .
If the question can be reformulated according to the rules set out in the certificate , edit it .

    1 answer 1

    The underlined line subscribes the UpdateUserInfo handler to the UpdateUserInfo event.
    Thus, when the _view.UserIdChanged event _view.UserIdChanged , the UpdateUserInfo method will be called.

    • one
      Is it possible to rewrite this line without lambdas? If so, how? - J.John
    • 6
      @ J.John I'm sure yes. Try: _view.UserIdChanged += UpdateUserInfo; . - Dmitry D.
    • one
      Judging by the format of the lambda, yes, you can subscribe by the method itself, and the lambda was apparently shoved there from the great mind, or you forgot to remove the same reason. - rdorn