delegates

Difference between events and delegates and its respective applications

I don't see advantages of using events over delegates, other than being syntactical sugar . Perhaps I am misunderstanding, but it seems that events is just a placeholder for delegate. Would you guys explain to me the differences and when to use which? what are the advantages and disadvantages? Our code is heavily rooted with events, a...

Delegates: Predicate Action Func

Can someone provide a good explanation (hopefully with examples) of these 3 most important delegates:Predicate Action Func. What other delegates a csharp developer should be aware of? How often do you use them in production code? thanks ...

What's the best way to communicate between view controllers?

Hi Stack Overflow Gang, Being new to objective-c, cocoa, and iPhone dev in general, I have a strong desire to get the most out of the language and the frameworks. One of the resources I'm using is Stanford's CS193P class notes that they have left on the web. It includes lecture notes, assignments and sample code, and since the course ...

What does the operator '=>' mean in C#?

What does the '=>' in this statement signify? del = new SomeDelegate(() => SomeAction()); Is the above declaration the same as this one? del = new SomeDelegate(this.SomeAction); Thanks. ...

Using a Delegate with Messages

I'm learning about delegates and think I may have found a use for one. Basically what I have is a series of string properties that take in a minimum value and a maximum value, like so: string weightInvalid(min as int32, max as int32) There are several messages like this, all with unique messages but all sharing the same signature of ...

Generic delegate or generic cast problem

How can i make the following code compile? Action<MyClass<object, object>> func = x => Console.WriteLine(x.ToString()); public void Apply<T1, T2>(MyClass<T1, T2> target) { func.Invoke(target); } I know it doesnt work because a MyClass<T1, T2> isnt a MyClass<object, object>, but what can i do? Can i make the f...

action delegate with zero parameters

I see this line in many online examples of using the Action delegate: public event Action MyEvent; But when I try it in my own code, I get this the error Using the generic type 'System.Action' requires '1' type arguments The documentation certainly describes a form of Action without any type parameter. What am I missing? ...

Delegate.CreateDelegate vs DynamicMethod vs Expression

Questions about Making reflection fly and exploring delegates... If I need to create delegates Func<T, TResult> to methods on dynamically loaded types I could potentially use (1) Delegate.CreateDelegate (2) DynamicMethod (3) Expression trees. Lets say the set of dynamically loaded types/methods are reflected once at application startup...

Passing a Function (with parameters) as a parameter?

I want to create a generic to which I can pass a function as a parameter, however this function may include parameters itself so... int foo = GetCachedValue("LastFoo", methodToGetFoo) Such that: protected int methodToGetFoo(DateTime today) { return 2; // example only } Essentially I want to have a method that will check the cache f...

Correct way to use UIActionSheet Delegate? Pointers Mapped to identical Memory

I am using the actionSheet variable passed by actionSheet:didDismissWithButtonIndex: to compare the calling actionSheet to a list of UIActionSheet variables in my class. This seems to be the way the delegate method was designed to differentiate between events. - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(N...

Why can't I put a delegate in an interface?

Why can't I add a delegate to my interface? ...

Possible to instantiate and invoke a delegate by name?

I'm trying to figure out if it is possible to instantiate and invoke a delegate by name, rather than explicitly. I think the code belows explains it fairly well....I want to accept a function name, and then instantiate the delegate based on that. In the example I use a select case, but I want to eliminate that and just use the methodNa...

How are user-defined delegates used and created in C# ?

I've used delegates when designing win forms in .NET... i.e. drag/drop a button, double click, and fill in the myButton_click event. I want to understand how to create and use user-defined delegates in C#. How are user-defined delegates used and created in C# ? ...

How can I pass an event to a function in C#?

I am looking to pass an event to a helper function. This function will attach a method to the event. However, I am having trouble properly passing the event. I have tried passing a EventHandler<TEventArgs>. It compiles, but events are not attached (but are still added; it seems a copy of the event handler is made). For example, if I...

How do I create delegates in Objective-C?

I know how delegates work, and I know how I can use them. But how do I create them? ...

Delegate Usage : Business Applications

Background Given that 'most' developers are Business application developers, the features of our favorite programming languages are used in the context of what we're doing with them. As a C# / ASP.NET Application developer, I tend to only use delegates when dealing with UI events. In fact (and this is part of my inexperience showing),...

When would I use a delegate in asp.net?

I'm always looking for a way to use all the tools I can and to stretch myself just beyond where I am at. But as much as I have read about delegates, I can never find a place to use them (like Interfaces, Generics, and a lot of stuff, but I digress.) I was hoping someone could show me when and how they used a delegate in web programming...

Explain how delegates work in the following code?

I am curious on how the following code works, especially the part the contains the delegate stuff since I am new to it. Also, are there any bottlenecks in the code, for example, would using a SortedDictionary be better than using a List and then sorting it using LINQ? Ok, here is the code: public class ColorManager { private List<...

When chaining .NET delegates, how are the original instances (re)used?

Say I have the following C# code: Action a = TestMethod; Action b = TestMethod; Action c = b; b += a; Tests indicates that b is not the same instance as c, so clearly the + operator seems to create a new instance of the delegate. Is this a correct assumption? Does it reuse the b-instance internally, or does it just copy the method/tar...

Callback Function

I have a method called funct which i want to have as my callback function when i am using the beingreceive socket method in c#. s.BeginReceive(buffer, 0, buffer.Length, System.Net.Sockets.SocketFlags.None, new AsyncCallback(funct), null); The error that am getting is: No overload for 'funct' matches delegate 'System...