delegate keyword vs. lambda notation
Once it is compiled, is there a difference between: delegate { x = 0; } and () => { x = 0 } ? 6 Answers 6
Once it is compiled, is there a difference between: delegate { x = 0; } and () => { x = 0 } ? 6 Answers 6
Does the Java language have delegate features, similar to how C# has support for delegates? 15 Answers 15
Is it possible to unsubscribe an anonymous method from an event? If I subscribe to an event like this: void MyMethod() { Console.WriteLine(“I did it!”); } MyEvent += MyMethod; I can un-subscribe like this: MyEvent -= MyMethod; But if I subscribe using an anonymous method: MyEvent += delegate(){Console.WriteLine(“I did it!”);}; is it possible to unsubscribe … Read more
What are the differences between delegates and an events? Don’t both hold references to functions that can be executed? 11 Answers 11
This question already has answers here: Where do I use delegates? [closed] (8 answers) Closed 8 years ago. I’m relatively new in C#, & I’m wondering when to use Delegates appropriately. they are widely used in events declaration, but when should I use them in my own code and why are they useful? why not … Read more
weak references don’t seem to work in Swift unless a protocol is declared as @objc, which I don’t want in a pure Swift app. This code gives a compile error (weak cannot be applied to non-class type MyClassDelegate): class MyClass { weak var delegate: MyClassDelegate? } protocol MyClassDelegate { } I need to prefix the … Read more
I know how delegates work, and I know how I can use them. But how do I create them? 19 s 19 An Objective-C delegate is an object that has been assigned to the delegate property another object. To create one, you define a class that implements the delegate methods you’re interested in, and mark … Read more
This question already has answers here: Delegates: Predicate vs. Action vs. Func (8 answers) Closed 7 years ago. With real examples and their use, can someone please help me understand: When do we need a Func<T, ..> delegate? When do we need an Action<T> delegate? When do we need a Predicate<T> delegate? 3 s 3
I have several methods all with the same parameter types and return values but different names and blocks. I want to pass the name of the method to run to another method that will invoke the passed method. public int Method1(string) { // Do something return myInt; } public int Method2(string) { // Do something … Read more
I understand lambdas and the Func and Action delegates. But expressions stump me. In what circumstances would you use an Expression<Func<T>> rather than a plain old Func<T>? 1Best Answer 11 When you want to treat lambda expressions as expression trees and look inside them instead of executing them. For example, LINQ to SQL gets the … Read more