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;
            };
        }
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,481 questions
0 comments No comments
{count} votes

Accepted answer
  1. Alan Farias 750 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