Hello everyone, I am passing a course on c #
there is a line:
// Невозможно открепить ранее присоединенный анонимный метод. instance.MyEvent -= delegate { Console.WriteLine("Анонимный метод 1."); };
as noted by the author of the course - It is impossible to detach the previously attached anonymous method
but, after a while, an amendment is made to the fact that an anonymous method acting as an event handler is still possible to detach, but "... you will see this detachment technique in the next course."
The question arises:
1) Why doesn’t the above method of lambda method detaching work?
2) How to detach the lambda method?
3) If the lambda method is not so easily detached, can I (I don’t remember exactly if the lambda method takes the parameters into the constructor) pass a call to its constructor, for example, some other usual method, for example, the malicious method we created is a dirty trick) which will be called on this event - via the lambda method - caused by this event? For example, in case of an event - "clicking with a mouse" (written by us and not ready (standard) if such is available) - through a lambda method to call some kind of "malicious method"