About delegates and events?

Answer Posted / kishoreg

Delegates in C#
If we look at C++ there is a feature called callback
function. This feature uses Pointers to Functions to pass
them as parameters to other functions. Delegate is a
similar feature but it is more type safe, which stands as a
stark contrast with C++ function pointers. A delegate can
hold reference/s to one more more functions and invoke them
as and when needed.
Any delegate is inherited from base delegate class of .NET
class library when it is declared. This can be from either
of the two classes from System.Delegate or
System.MulticastDelegate
If the delegate contains a return type of void, then it is
automatically aliased to the type of
System.MulticastDelegate

Events in c#
Delegate usefulness does not just lie in the fact that it
can hold the references to functions but in the fact that
it can define and use function names at runtime and not at
compile time. A large goal of design delegates is their
applicability in events model of .Net. Events are the
actions of the system on user manipulations (e.g. mouse
clicks, key press, timer etc.) or any event triggered by
the program

Example can be seen at
http://www.codersource.net/csharp_delegates_events.html

Is This Answer Correct ?    6 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Does c# provide copy constructor?

753


What is mvc in c#?

639


What is readline c#?

647


Is void a class?

627


Is .net and c# the same?

721


How we can create an array with non-default values?

706


What is hierarchical inheritance in c#?

657


What is console readkey ()?

701


Write a program in C# for checking a given number is PRIME or not.

837


What is .net console?

735


What is the boxing and unboxing in c#?

669


Distinguish between array and arraylist in c#?

726


Hi to all..I have to create an intranet application on C#.NET windows Application so please please let can you people help me as iam new in .NET and if u have any samples or website address from where i can get sample please let know.

3992


What is the advantage of singleton class?

677


What are the value types in c#?

712