I created a code sample:
class Program { static void Main(string[] args) { var x = new ActionTestClass(); x.ActionTest(); var y = x.Act.Target; } } public class ActionTestClass { public Action Act; public void ActionTest() { this.Act = new Action(this.ActionMethod); } private void ActionMethod() { MessageBox.Show("This is a test."); } }
When I do this along this path, y will be an object of type ActionTestClass (which is created for x). Now when i change the line
this.Act = new Action(this.ActionMethod);
to
this.Act = new Action(() => MessageBox.Show("This is a test."));
y (Target of the Action) will be null. Is there a way that I can get the target (in the sample ActionTestClass object) also in the way of using an anonymous action?
source share