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

Framerate independent event in Unity3D

I use the libpd4unity package to communicate with Pure Data. I receive a bang from Pure Data with LibPD.Bang. On a bang event I play sound by FMOD. Problem is, that I receive bangs frequently, for example once every 500 ms but event doesn't trigger…
ATHellboy
  • 704
  • 3
  • 15
  • 30
4
votes
2 answers

Why Partial delegates are not allowed in C#?

Recent interview question is If C# language allow us create partial delegates what are the consequences will you meet? Help me to understand the reason. Thanks in advance.
Amutha
  • 67
  • 2
4
votes
6 answers

Implementing Delegate Pattern in Objective-C

I am building a class that handles NSURLConnection requests. To allow other classes to use this class, I would like to allow the main class to call a delegate when connectionDidFinishLoading is fired. I've looked through lots of documentation, but…
pixel
  • 5,298
  • 8
  • 35
  • 32
4
votes
1 answer

Define the app delegate as a constant?

I'm trying to write an iPhone application, and I have a problem. I have declared a constant as the app delegate inside a class #define ikub (iKubMobileAppDelegate *)[[UIApplication sharedApplication] delegate] And when I need to get the size of an…
Olsi
  • 929
  • 2
  • 12
  • 26
4
votes
2 answers

What is the purpose of this delegate usage?

Whilst poking around some code using a .NET Reflector for an app I don't have the source code for, I found this: if (DeleteDisks) { using (List>.Enumerator enumerator3 = list.GetEnumerator()) { MethodInvoker invoker2 = null; …
Kev
  • 118,037
  • 53
  • 300
  • 385
4
votes
7 answers

"Cannot find protocol declaration for ..." in adopting class objective c

I'm a little frustrated at the moment with the custom delegate process in objective-c. I've used the design pattern a few times already and have a pretty good understanding of how it works. I've searched the internet for 2 hours trying to find what…
RBI
  • 803
  • 2
  • 14
  • 25
4
votes
2 answers

C#: Less ugly syntax for creating delegate lists?

I'm building a system a bit like LINQ, and in doing it, am trying to support polymorphic callback handler lists, and am running into several kinds of problems. The short way to ask my question is to just show you some code. My new system supports…
Ken Birman
  • 1,088
  • 8
  • 25
4
votes
5 answers

C# Internal delegate and public Event

I'm currently developing a tiny technical Framework that is independant of any applications. Business code just refers to this Framework. According this article : http://msdn.microsoft.com/en-us/library/5z57dxz2.aspx (exemple 2), we need to provide…
Arnaud F.
  • 8,252
  • 11
  • 53
  • 102
4
votes
1 answer

How to set delegate of UITextField in separate class in Swift?

I'm trying to implement UITextFieldDelegate in separate class, but it didn't working: class ViewController: UIViewController { @IBOutlet var TextField: UITextField! override func viewDidLoad() { super.viewDidLoad() let…
JasonTW
  • 55
  • 8
4
votes
1 answer

Is it possible to call private delegate by reflection? if Yes then How? if No then What is the reason?

I am testing Console application on Reflection to call the delegate whose access modifier is private. The code looks like this: public class EventPublisher { private delegate void PrivateDelegate(string message); public…
xdrnc
  • 260
  • 2
  • 11
4
votes
3 answers

Fail in assigning self.delegate it produce unrecognized selector sent

I'm a new in iOS, and I have trouble in implementing @protocol so sorry if you think this is an easy thing.. i've been searching around stackoverflow.com, the webs and also try uncle Google for a while and I decided to ask here... The main idea is…
DoogyHtw
  • 341
  • 1
  • 3
  • 16
4
votes
2 answers

Invoking operations asynchronously with expiration

I have a classic asynchronous message dispatching problem. Essentially, I need to asynchronously dispatch messages and then capture the message response when the dispatch is complete. The problem is, I can't seem to figure out how to make any one…
JoeGeeky
  • 3,746
  • 6
  • 36
  • 53
4
votes
6 answers

How to identify an anonymous function

I have a class that creates a List> and holds on to them until a later time. This class can add and remove delegates from this list. This works well as long as people don't get too fancy. To combat anonymous function (which can't be…
Steve
  • 11,763
  • 15
  • 70
  • 103
4
votes
1 answer

Dictionary with Delegates of different types: Cleaner, non string method names?

There has to be a cleaner method. Currently I have: ... Constructor() { parseDictionary = new Dictionary() { {typeOfStream.SOME_ENUM_VAL,…
Nick
  • 739
  • 11
  • 22
4
votes
1 answer

How to have Lists with events upon change in List

I'm a newbie in events. This example shows that an event is invoked every time the ArrayList is changed. I would like to know how to do it using generics. To you implement IList or extend List? I tried to code it but I'm stuck. using…
yoitsfrancis
  • 4,278
  • 14
  • 44
  • 73