I am trying to create a delegate for the struct method for a specific instance. However, it turns out that a new instance of the structure is created, and when I call the delegate, it executes this method on top of the newly created instance, and not the original.
static void Main(string[] args) { Point A = new Point() { x = 0 }; Action move = A.MoveRight; move();
Actually, what happens in this example is that a new instance of struct Point is created on the delegate creator, and the method that is called through delagate is executed on it.
If I use a class instead of a structure, the problem is resolved, but I want to use a struct. I also know that there is a solution with creating an open delegate and passing the structure as the first parameter to the delegate, but this solution seems too heavy. Is there any simple solution to this problem?
source share