2. Static Constructor
• A static constructor is used to initialize any
static data, or to perform a particular action
that needs to be performed once only. It is
called automatically before the first instance is
created or any static members are referenced.
4. String Methods
• IndexOf:
• This method finds the first index of the char
argument. It returns -1 if the char was not
found.
5. Introduction
• Delegate is a type which holds the method reference in an
object. It is also referred to as a type safe function pointer.
• A delegate is a type that defines a method signature.
• When you instantiate a delegate, you can associate its
instance with any method with a compatible signature.
6. Why Delegates
• Encapsulating the method's call from caller
• Effective use of delegate improves the
performance of application
• Used to call a method asynchronously
7. Multicasting of a Delegate
• Delegate objects can be composed using the
"+" operator.
• composed delegate calls the two delegates it
was composed from.
• Only delegates of the same type can be
composed.
8. Events
• Events are basically a user action like key
press, clicks, mouse movements etc., or some
occurrence like system generated
notifications. Applications need to respond to
events when they occur. For example,
interrupts. Events are used for inter-process
communication.
9. Using Delegates with Events
• The events are declared and raised in a class
and associated with the event handlers using
delegates.
• The class containing the event is used to
publish the event. This is called the publisher
class. Some other class that accepts this event
is called the subscriber class. Events use the
publisher-subscriber model.
10. • A publisher is an object that contains the
definition of the event and the delegate. The
event-delegate association is also defined in
this object. A publisher class object invokes
the event and it is notified to other objects.
11. • A subscriber is an object that accepts the
event and provides an event handler. The
delegate in the publisher class invokes the
method (event handler) of the subscriber
class.
12. Events
• An event is a delegate type class member that
is used to provide notification to other objects
that an event has occurred.
• The client object can add event handler to
handle the event.
14. Declaring Event
• Modifier event type event_name ;
• Public event Eventhandler click;
• Public event RateChange rate;
15. Events and Delegates
• Since events are based on delegates , we must
first declare delegate and then declare an
instance of delegate using keyword event.