delegates

Overwriting delegate.ToString()

private delegate int Operate(int x, int y); Operate usedOperator; int Add(int x, int y) { return x + y; } usedOperator.ToString() should return either "+" "-" or whatever method the delegate currently contains. Is this possible somehow? EDIT: Alternatives to the delegate approach would be fine too. I basically am writing a pro...

C# - How can I "overload" a delegate?

First, I was reading some forums and the help in MSDN and all says that a delegate can't be overloaded. Now, I want to have something like this: public delegate void OneDelegate(); public delegate void OneDelegate(params object[] a); public void DoNothing(params object[] a) {} public void DoSomething() { /* do something */ } private ...

What is the "correct" way to initialize a C# delegate?

C# delegates have always been difficult for me to grasp and so I was very happy to stumble across logicchild's article on The Code Project web site titled "C# Delegates: Step by Step". He has a very succinct way of explaining C# delegates and I can recommend it to you. However, in trying out the examples, I see that are two ways to initi...

Delegate to an instance method cannot have null 'this'.

I am developing a C# .NET 2.0 application wherein at run-time one of two DLLs are loaded depending on the environment. Both DLLs contain the same functions, but they are not linked to the same address-offset. My question is regarding the function delegates in my application code. public class MyClass { public delegate int MyFuncti...

How would I use a linq expression to create a delegate with parameters?

Hi, I found your code example below extremely helpful, however I don't understand the use of expressions in the code... I am looking to modify this method to accept a delegate with a params object[] parameter.. any pointers would be greatly appreciated. Simon Bridge ([email protected]) class EventProxy { static public Delegate C...

jquery ajax problem

Hi again everyone, thanks for every help that you guys have given me so far !! :D and now, i encounter some problem on me using jquery and ajax i am fetching all of my user's photos from my database, calling them out into a grid and then applying a jquery pagination plug-in 'pajinate' using this code $(function(){ $('#talent_pagin...

Can a Delegate have an optional parameter?

I have the below code that was working fine until I tried adding the bool NetworkAvailable = true portion. Now I get a Method name expected compile time exception at Line 4 below. void NetworkStatus_AvailabilityChanged(object sender, NetworkStatusChangedArgs e) { var networkAvailable = e.IsAvailable; SetUpdateHUDConnectedMode d =...

Is this a correct syntax for generic delegates and events?

I'm reading the msdn library topic about genrics . There is an example of declaring event wiht generic delegates, but is it correct? // Code block 8. Generic event handling public delegate void GenericEventHandler<S,A>(S sender,A args); public class MyPublisher { public event GenericEventHandler<MyPublisher,EventArgs> MyEvent; pu...

jquery, using API event issue, delegate, live event.

Hello everybody, I have a question what I try to understand for a wile. When I am using API feed with jquery I always have a problem, it is "click", "ready" ... events, which makes me to apply some hacks or to choose another way. For example Flickr API: $.each(data.photoset.photo, function(i, rPhoto){ var basePhotoURL =...

Problem in Updating DataGridView via a thread ( when Scrolling )

Hi Experts, I am stuck with this problem of mine and it will be great help if someone solves this problem for me What I am trying to do is : 1) Intialize a DataTable datatable in form load event and assign its defaultview to a datagridview dgvresult 2) On click of a button start an STA thread (I am actually working with WatIN IE ...

Objective-C equivalent to Java's anonymous classes in class methods

I want to set the delegate of an object inside a class method in Objective-C. Pseudo-code: + (ClassWithDelegate*) myStaticMethod { if (myObject == nil) { myObject = [[ClassWithDelegate alloc] init]; // myObject.delegate = ? } return myObject; } In Java I would simply create an anonymous class that implement...

what is the use of delegates in C#?

Possible Duplicate: When would you use delegates in C#? On what condition should we use delegates ...

iPhone: delegate of ModalViewController

Hey, I have an issue by setting the delegate property for a ViewController which is presented modally. The code below is a modified copy of the example code for Presenting a View Controller Modally. AddContactPersonTableViewController *addController = [[AddContactPersonTableViewController alloc] initWithNibName:@"AddContact...

UITextView delegates problem

Hi, I am trying to access the UITextView delegates and have a problem I have a UIViewController with the UITextViewDelegate protocol and a Nib containing the textView. If I set the delegate inside viewDidLoad like "textView.delegate = self" and I touch the textView, the app crashes without logging errors. If I start editing the textVi...

Android - Anything similar to the iPhone SDK Delegate Callbacks?

I just switched over from iPhone to Android and am looking for something similar to where in the iPhone SDK, when a class finishes a certain task, it calls delegate methods in objects set as it's delegates. I don't need too many details. I went through the docs and didn't find anything (the closest I got was "broadcast intents" which se...

How to get the referred string of an Action<string> delegate?

I have a method that expects an Action<string> I call the method as follows: commandProcessor.ProcessCommand(s=> ShowReceipt("MyStringValue")) ProccessCommand(Action<string> action) { action.Invoke(...); // How do I get the reffered string? } Do I have to use Expression<Action<string>> ? If so, how do I get the parameter values? ...

Asynchronous delegate invocation

How do i pass method to asynchronous delegate invocation, so that it could be explicitly processed asynchronously on second processor? Thanks in advance. ADDED: I had problem with encoding internet so sorry for upper case. I have tried: BTW Have no javascript enabled in browser so I can't add comments to this post. Will be editing this...

How to cast anonymous type to specified cast to get all its properties

This code is returning me a list that I am trying to pass to another function. _ucItem.lblItemName.Text = itemRow.Field<string>("ITEM_NAME").ToString(); _ucItem.pbxItemImg.Image = itemRow.Field<string>("IMAGE").ToString(); _ucItem.lblItemName.Text = itemRow.Field<string>("FK_ITEM_ID").ToString(); Here I want to replace this set of lin...

Threads and delegates - I dont fully understand their relations.

I wrote a code that looks somewhat like this: Thread t = new Thread(() => createSomething(dt, start, finish) ); t.Start(); and it works (sometimes it almost feel like there are multiple threads) yet I don't use any delegates. What is the meaning of a tread without a delegate If a delegate is necessary - then please tell me what and...

Remove duplicated code - using Action

Hi I have the following code which obviously has some duplication. I'm sure this could be removed using a delegate or Action but can't quite grasp it. anyone got any ideas? public void DealStartingCards() { for (int i = 0; i < 3; i++) { foreach (var player in Players) { ...