Questions tagged [delegates]

Delegates can refer to several concepts. An object can rely on another (a delegate) to perform a function. Delegation can also refer to programming language feature making use of the method lookup rules for dispatching self-calls. In C#, a delegate defines which method to call when an event is triggered.

In object-oriented programming, there are three related notions of delegation.

Most commonly, delegation refers to a programming language feature making use of the method lookup rules for dispatching so-called self-calls. Delegation as a language feature supports the prototype-based programming model.

Delegation can also refer to one object relying upon another to provide a specified set of functionalities. In research, this is often referred to as consultation or as aggregation in modeling.

In C#, a delegate is a way of telling which method to call when an event is triggered, keeping the method type.

A Delegate is a type that safely encapsulates a method, similar to a function pointer in C and C++. Unlike C function pointers, delegates are object-oriented, type safe, and secure.

Official Source

11320 questions
4
votes
1 answer

Delegate and IBAction

They seem to accomplish the same thing in Objective C. What can one do without the other?
user4951
  • 32,206
  • 53
  • 172
  • 282
4
votes
2 answers

How to dismiss multiple presentModalViewControllers and get back to the root Tab Bar controller?

I have an application that shows a presentModalViewController upon launch. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application…
Strong Like Bull
  • 11,155
  • 36
  • 98
  • 169
4
votes
0 answers

How do I subscribe a python function to a C# .Net delegate method using pythonnet? (TypeError: unsupported operand type(s))

I can't subscribe my python function to a delegate method inside a .dll lib file written in c# net. This lib is written to communicate with a device. I successfully import the lib via pythonnet. I can use some methods of the lib like sending…
cquests
  • 41
  • 2
4
votes
1 answer

is it possible to add multiple selectors in a delegate function in jquery?

Something like creating a namespace/sub-module for my scripts concerning a module in my app? Like say I only want to delegate certain tasks to elements inside a certain div like say #submodule1. Can I do something like this: $("#submodule1") …
corroded
  • 21,406
  • 19
  • 83
  • 132
4
votes
1 answer

Does casting an anonymous lambda to a strongly typed delegate disable compiler caching?

I'm trying to understand an edge-case of compiler powered delegate caching to avoid memory allocation. For example, to my understanding, this delegate gets cached to a single instance and reused, because it doesn't close over any local…
Lazlo
  • 8,518
  • 14
  • 77
  • 116
4
votes
1 answer

Write anonymous expression as lambda expression

How to write the same 'Anonymous Expression' in 'Lambda Expression.' namespace AnonymouseAndLambdaExpression { // Delegate public delegate bool NumberHandler(int number); class Program { static void Main(string[] args) …
Rehan Shah
  • 1,505
  • 12
  • 28
4
votes
2 answers

iPhone app crashes when user exits UITableView with MBProgressHUD running in separate thread

In my app, I have a UITableViewController which loads calculated data from my Core Data store. This can take quite some time and hangs the main thread, so to give the user visual feedback, I have installed the MBProgressHUD widget which will show a…
Jason
  • 14,517
  • 25
  • 92
  • 153
4
votes
2 answers

Trying to create a dynamic delegate

I am loading a dll using loadfrom and iterating thru the methods to find ones that match a signature. When I find it I want to assign it as a delegate so I can call it later. This is what I am doing... foreach (MethodInfo method in methodInfos) { …
Jeff
  • 53
  • 1
  • 4
4
votes
1 answer

Hook up a Delegate to an Event using reflection?

I have 2 DLL, A.dll contains: namespace Alphabet { public delegate void TestHandler(); public class A { private void DoTest() { Type type = Assembly.LoadFile("B.dll").GetType("Alphabet.B"); …
ByulTaeng
  • 1,269
  • 1
  • 21
  • 40
4
votes
5 answers

Hash a delegate function in C#

How can I get a hash of a delegate function in C#. I want to be able to tell if different delegates are being sent into my function. My code looks something like this: public string GetContent(Func isValid) { // Do some…
Noah
  • 13,821
  • 4
  • 36
  • 45
4
votes
2 answers

Setting up delegates in container view

I have a container view in my Storyboard that displays another view controller that I already programmed and stuff. I want to communicate between the main View Controller and the contained-view controller. I know how to use delegates and I am…
dvd.Void
  • 339
  • 1
  • 5
  • 21
4
votes
2 answers

Why use delegates when using object remoting MarshalByRefObj?

My app allows plugins, I have a Core class (MarshalByRefObj) that plugins must inherit and this class offers various functionality. Now my question is, when this class is instantiated on main app domain and passed to the plugin in different app…
Alex Maher
  • 83
  • 2
  • 6
4
votes
1 answer

Detect USB devices with Swift 4 on macOS

I found the code bellow (here), but I am a newbie with Swift so I can't make it work as it is needed. The code works fine, I had only to make very small changes on it, and once it runs it shows the devices added. Now I cant figure out how, to once…
Magno
  • 387
  • 4
  • 13
4
votes
2 answers

How does linq Expression assignment work on a language syntax level

TLDR: How does this compile? class A{}; Expression> e = x => 24; // I don't understant what makes this compile // and what happens at this assignment What is the minimum class E to be able to…
bolov
  • 72,283
  • 15
  • 145
  • 224
4
votes
1 answer

Create a delegate with a dynamic injected class

I'm changing a processing algorithm I've made from reflection to delegate since it handles huge data and it is having performance issues(as I have learned here). So my old code is a simple reflection as shown below: var result =…
DontVoteMeDown
  • 21,122
  • 10
  • 69
  • 105