Hi
Can someone tell me what the advantage of a delegate is? Maybe an example
code would help
Thanks
Jim 3 2361
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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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: 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: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |