Hi
Can someone tell me what the advantage of a delegate is? Maybe an example
code would help
Thanks
Jim 3 2371
Hi,
A delegate allow you to call a different method each time, or choose at
runtime what method to call, as long as a method has the same signature that
the delegate you can use it.
Cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Jimmy" <be****@gmail.c om> wrote in message
news:uL******** *****@TK2MSFTNG P15.phx.gbl... Hi
Can someone tell me what the advantage of a delegate is? Maybe an example code would help
Thanks
Jim
Ignacio
ok but why would you use this? what is the advantage of a delegate? when
would you use it?
Jimmy
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us > wrote
in message news:OO******** ******@TK2MSFTN GP09.phx.gbl... Hi,
A delegate allow you to call a different method each time, or choose at runtime what method to call, as long as a method has the same signature
that the delegate you can use it.
Cheers,
-- Ignacio Machin, ignacio.machin AT dot.state.fl.us Florida Department Of Transportation "Jimmy" <be****@gmail.c om> wrote in message news:uL******** *****@TK2MSFTNG P15.phx.gbl... Hi
Can someone tell me what the advantage of a delegate is? Maybe an
example code would help
Thanks
Jim
Jimmy <be****@gmail.c om> wrote: ok but why would you use this? what is the advantage of a delegate? when would you use it?
For event handlers, or whenever you want a function pointer, basically.
You could think of it as a "one method interface" if you want, but you
don't need to explicitly implement it, or you can pseudo-implement it
several times in the same class (just by giving several different
methods the same signature as the delegate). You can also build
delegate instances from static methods.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Minh Khoa |
last post by:
Please give me more information about delegate and its usage?
Why do i use it and when?
|
by: ^MisterJingo^ |
last post by:
Hi all,
I've been trying to get my head around delegates. The book i'm using
had a single example, not much explaination, and didn't show how to set
up a delegate and pass variables in and out of the functions it refers
to. So I've been playing around and came up with he following code. I
know it doesn't do much, but I just wanted to fit together delegates
and parameter passing:
//////////////// Code start
|
by: Jeff S |
last post by:
Please consider this sample code: It registers a delegate with an event.
p1.FirstNameChanged += new Person.NameChanged(p1_FirstNameChanged);
Now the following code removes the delegate:
p1.FirstNameChanged -= new Person.NameChanged(p1_FirstNameChanged);
The above line that removes the delegate confuses me. It works - buy why
must we use the 'new' keyword? The delegate already exists and is
"registered" with the event. I would think...
|
by: Ant |
last post by:
Hello,
Very simple question but one I need clarified.
Which part of the statement below is considered the 'delegate'?
Is it the 'new System.EventHandler'
or the
btnAccept_Click?
or is it the piece of code which doesn't appear here, but abstracts the
btnAccept_Click method?
|
by: David Veeneman |
last post by:
I have several events that pass a value in their event args. One event
passes an int, another a string, another a DateTime, and so on. Rather than
creating a separate set of event args for each type, I have created a
generic event args class that looks like this:
public class ItemChangingEventArgs<T>
{
...
}
| |
by: Quimbly |
last post by:
I'm having some problems comparing delegates. In all sample projects I
create, I can't get the problem to occur, but there is definitely a problem
with my production code.
I can't give all the code, as there's simply too much, but here's the
general gist:
I have a connection object which connects to a custom back-end server of one
type or another. Clients of this connection object send requests via a
method (e.g....
|
by: matsi.inc |
last post by:
I am looking to make something like a delegate that i can use in my
projects but am having a hard time getting started.
The behavior I am most interested in is how a delegate changes it's
Invoke method dynamically to match the arguments supplied to it when it
is defined. For example...
public delegate void MyDelegate(string myString, int myInt);
|
by: damiensawyer |
last post by:
Hi,
Can someone please explain to me something about delegates?
My understanding is as follows. A delegate is basically an object that
can hold a reference to a "method" somewhere. That is, it's
essentially a pointer to a piece of code somewhere else in memory.
It therefore (to me anyway) makes sense to define delegates with their
signatures and be able to use those signatures at different points in
|
by: raylopez99 |
last post by:
Here is a good example that shows generic delegate types. Read this
through and you'll have an excellent understanding of how to use these
types. You might say that the combination of the generic delegate
type expression in just the right place and a well-named method means
we can almost read the code out loud and understand it without even
thinking.
Note that since 'boxing' and 'unboxing' is involved (I think), you
don't get what you...
|
by: vcquestions |
last post by:
Hi.
Is there way to have a function pointer to a delegate in c++/cli that
would allow me to pass delegates with the same signatures as
parameters to a method?
I'm working with managed code. Let's say we have 2 delegates:
public delegate void FirstDelegate( int i );
public delegate void SecondDelegate( int i );
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |