How to write code like this without lambda?

nean 40 Reputation points
2023-05-11T12:09:24.38+00:00

Parameters that require the ability to use the method.

public void DoSomething(Window _this)
        {
            _this.Closing += (_sender, _e) =>
            {
                _this.Top = 0;
            };
        }
Developer technologies | C#
0 comments No comments
{count} votes

Accepted answer
  1. Alan Farias 755 Reputation points
    2023-05-11T14:27:51.23+00:00

    I'm not really sure I understand what you need. See if it looks something like this (not final code, just a demo of concept):

    public void DoSomething(Window _this)
    {
        _this.Closing += OnWindowClosing;
    }
    
    private void OnWindowClosing(object sender, System.ComponentModel.CancelEventArgs e)
    {
        ((Window)sender).Top = 0;
    }
    
    
    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.