SlideShare uma empresa Scribd logo
1 de 8
Baixar para ler offline
Events and
Delegates
        Programming in C#




           tnngo2@gmail.com
Delegates
Delegates

         are objects that contain references to method that need to be
invoked instead of containing the actual method names.

        call any method, which is identified only at runtime.

        to associate a delegate with a particular method, the method must
have the same return type and parameter type as that of the delegate.
1. Declaring delegates




2. Create the method to be referenced
3. Instantiating delegates




4. Call
https://gist.github.com/2427445
Anonymous methods
Events
Events

         a way for a class to provide notifications to clients of that
         class when some interesting thing happens to an object.
Implement Events

      1. Define a public delegate for the event
      2. Create the event using the delegate
      3. Subscribe to listen and handle the event
      4. Raise the event

      https://gist.github.com/2427324

Mais conteúdo relacionado

Mais procurados

Evolution of C# delegates
Evolution of C# delegatesEvolution of C# delegates
Evolution of C# delegatesmbaric
 
C# Delegates and Event Handling
C# Delegates and Event HandlingC# Delegates and Event Handling
C# Delegates and Event HandlingJussi Pohjolainen
 
Lambda Expressions in C# From Beginner To Expert - Jaliya Udagedara
Lambda Expressions in C# From Beginner To Expert - Jaliya UdagedaraLambda Expressions in C# From Beginner To Expert - Jaliya Udagedara
Lambda Expressions in C# From Beginner To Expert - Jaliya UdagedaraJaliya Udagedara
 
Krazykoder struts2 annotations
Krazykoder struts2 annotationsKrazykoder struts2 annotations
Krazykoder struts2 annotationsKrazy Koder
 
Basic elements of java
Basic elements of java Basic elements of java
Basic elements of java Ahmad Idrees
 
Lesson11 more behavioural patterns
Lesson11 more behavioural patternsLesson11 more behavioural patterns
Lesson11 more behavioural patternsOktJona
 
object oriented programming using c++
 object oriented programming using c++ object oriented programming using c++
object oriented programming using c++fasalsial1fasalsial1
 
11 Using classes and objects
11 Using classes and objects11 Using classes and objects
11 Using classes and objectsmaznabili
 
Pragmas: Literal Messages as Powerful Method Annotations
Pragmas: Literal Messages as Powerful Method AnnotationsPragmas: Literal Messages as Powerful Method Annotations
Pragmas: Literal Messages as Powerful Method AnnotationsESUG
 
Basic concept of class, method , command line-argument
Basic concept of class, method , command line-argumentBasic concept of class, method , command line-argument
Basic concept of class, method , command line-argumentSuresh Mohta
 

Mais procurados (19)

C# Delegates
C# DelegatesC# Delegates
C# Delegates
 
Evolution of C# delegates
Evolution of C# delegatesEvolution of C# delegates
Evolution of C# delegates
 
C# Delegates and Event Handling
C# Delegates and Event HandlingC# Delegates and Event Handling
C# Delegates and Event Handling
 
Lambda Expressions in C# From Beginner To Expert - Jaliya Udagedara
Lambda Expressions in C# From Beginner To Expert - Jaliya UdagedaraLambda Expressions in C# From Beginner To Expert - Jaliya Udagedara
Lambda Expressions in C# From Beginner To Expert - Jaliya Udagedara
 
Interface
InterfaceInterface
Interface
 
Active Object
Active ObjectActive Object
Active Object
 
Krazykoder struts2 annotations
Krazykoder struts2 annotationsKrazykoder struts2 annotations
Krazykoder struts2 annotations
 
Constructors and Method Overloading
Constructors and Method OverloadingConstructors and Method Overloading
Constructors and Method Overloading
 
Intake 37 5
Intake 37 5Intake 37 5
Intake 37 5
 
Intake 37 2
Intake 37 2Intake 37 2
Intake 37 2
 
Java unit 7
Java unit 7Java unit 7
Java unit 7
 
Method overloading and constructor overloading in java
Method overloading and constructor overloading in javaMethod overloading and constructor overloading in java
Method overloading and constructor overloading in java
 
Basic elements of java
Basic elements of java Basic elements of java
Basic elements of java
 
Lesson11 more behavioural patterns
Lesson11 more behavioural patternsLesson11 more behavioural patterns
Lesson11 more behavioural patterns
 
object oriented programming using c++
 object oriented programming using c++ object oriented programming using c++
object oriented programming using c++
 
11 Using classes and objects
11 Using classes and objects11 Using classes and objects
11 Using classes and objects
 
C++
C++C++
C++
 
Pragmas: Literal Messages as Powerful Method Annotations
Pragmas: Literal Messages as Powerful Method AnnotationsPragmas: Literal Messages as Powerful Method Annotations
Pragmas: Literal Messages as Powerful Method Annotations
 
Basic concept of class, method , command line-argument
Basic concept of class, method , command line-argumentBasic concept of class, method , command line-argument
Basic concept of class, method , command line-argument
 

Destaque

C# Delegates, Events, Lambda
C# Delegates, Events, LambdaC# Delegates, Events, Lambda
C# Delegates, Events, LambdaJussi Pohjolainen
 
C# Starter L06-Delegates, Event Handling and Extension Methods
C# Starter L06-Delegates, Event Handling and Extension MethodsC# Starter L06-Delegates, Event Handling and Extension Methods
C# Starter L06-Delegates, Event Handling and Extension MethodsMohammad Shaker
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHPBradley Holt
 
Use cases combined
Use cases combinedUse cases combined
Use cases combinedocurtis1
 
Power Notes: Physical vs. Chemical
Power Notes:   Physical vs. ChemicalPower Notes:   Physical vs. Chemical
Power Notes: Physical vs. Chemicaljmori1
 
Angical fest 2011 2º dia 3
Angical fest 2011 2º dia 3Angical fest 2011 2º dia 3
Angical fest 2011 2º dia 3angical-piaui
 
Мой город - Кострома, №8
Мой город - Кострома, №8Мой город - Кострома, №8
Мой город - Кострома, №8Мой город
 
Aaaaaaaaaaaaaaaaaaaaaaaaaaaa
AaaaaaaaaaaaaaaaaaaaaaaaaaaaAaaaaaaaaaaaaaaaaaaaaaaaaaaa
Aaaaaaaaaaaaaaaaaaaaaaaaaaaacastelbi
 
My Sister's Keeper
My Sister's KeeperMy Sister's Keeper
My Sister's KeeperMagda_Diego
 
Javascript
JavascriptJavascript
Javascripttimsplin
 
ETEC 643 Health Hero
ETEC 643 Health HeroETEC 643 Health Hero
ETEC 643 Health Herosstjohn
 
Courts distribution - West Bank and Gaza
Courts distribution - West Bank and GazaCourts distribution - West Bank and Gaza
Courts distribution - West Bank and GazaJamil Salem
 
7 conferencia nacional_saude_anais
7 conferencia nacional_saude_anais7 conferencia nacional_saude_anais
7 conferencia nacional_saude_anaisJosé Roberto Sousa
 
Senandung Penantian
Senandung PenantianSenandung Penantian
Senandung PenantianSariana Csg
 

Destaque (20)

C# Delegates, Events, Lambda
C# Delegates, Events, LambdaC# Delegates, Events, Lambda
C# Delegates, Events, Lambda
 
C# Starter L06-Delegates, Event Handling and Extension Methods
C# Starter L06-Delegates, Event Handling and Extension MethodsC# Starter L06-Delegates, Event Handling and Extension Methods
C# Starter L06-Delegates, Event Handling and Extension Methods
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Module 2
Module 2Module 2
Module 2
 
Use cases combined
Use cases combinedUse cases combined
Use cases combined
 
Power Notes: Physical vs. Chemical
Power Notes:   Physical vs. ChemicalPower Notes:   Physical vs. Chemical
Power Notes: Physical vs. Chemical
 
Angical fest 2011 2º dia 3
Angical fest 2011 2º dia 3Angical fest 2011 2º dia 3
Angical fest 2011 2º dia 3
 
Campanita
CampanitaCampanita
Campanita
 
Aed1061
Aed1061Aed1061
Aed1061
 
Мой город - Кострома, №8
Мой город - Кострома, №8Мой город - Кострома, №8
Мой город - Кострома, №8
 
Aaaaaaaaaaaaaaaaaaaaaaaaaaaa
AaaaaaaaaaaaaaaaaaaaaaaaaaaaAaaaaaaaaaaaaaaaaaaaaaaaaaaa
Aaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
My Sister's Keeper
My Sister's KeeperMy Sister's Keeper
My Sister's Keeper
 
Javascript
JavascriptJavascript
Javascript
 
Fm1(a) genre
Fm1(a)   genreFm1(a)   genre
Fm1(a) genre
 
Tarea ingles
Tarea inglesTarea ingles
Tarea ingles
 
ETEC 643 Health Hero
ETEC 643 Health HeroETEC 643 Health Hero
ETEC 643 Health Hero
 
Kudavi 3.5.2016
Kudavi 3.5.2016Kudavi 3.5.2016
Kudavi 3.5.2016
 
Courts distribution - West Bank and Gaza
Courts distribution - West Bank and GazaCourts distribution - West Bank and Gaza
Courts distribution - West Bank and Gaza
 
7 conferencia nacional_saude_anais
7 conferencia nacional_saude_anais7 conferencia nacional_saude_anais
7 conferencia nacional_saude_anais
 
Senandung Penantian
Senandung PenantianSenandung Penantian
Senandung Penantian
 

Mais de Tuan Ngo

Introduction of cg program for portal 20120424 en
Introduction of cg program for portal 20120424 enIntroduction of cg program for portal 20120424 en
Introduction of cg program for portal 20120424 enTuan Ngo
 
Net framework
Net frameworkNet framework
Net frameworkTuan Ngo
 
15 anonymous methods, partial types and nullable types
15   anonymous methods, partial types and nullable types15   anonymous methods, partial types and nullable types
15 anonymous methods, partial types and nullable typesTuan Ngo
 
14 generics and iterators
14   generics and iterators14   generics and iterators
14 generics and iteratorsTuan Ngo
 
13 collections
13   collections13   collections
13 collectionsTuan Ngo
 
11 exception handling
11   exception handling11   exception handling
11 exception handlingTuan Ngo
 
9 properties & indexers
9   properties & indexers9   properties & indexers
9 properties & indexersTuan Ngo
 
10 namespace
10  namespace10  namespace
10 namespaceTuan Ngo
 
8 abstract classes and interfaces
8   abstract classes and interfaces 8   abstract classes and interfaces
8 abstract classes and interfaces Tuan Ngo
 
7 inheritance and polymorphism
7   inheritance and polymorphism7   inheritance and polymorphism
7 inheritance and polymorphismTuan Ngo
 
6 class and methods
6    class and methods6    class and methods
6 class and methodsTuan Ngo
 
3 statements and operators
3   statements and operators3   statements and operators
3 statements and operatorsTuan Ngo
 
4 c# programming constructs
4   c# programming constructs4   c# programming constructs
4 c# programming constructsTuan Ngo
 
1 get started with c#
1   get started with c#1   get started with c#
1 get started with c#Tuan Ngo
 
2 variables and data types
2   variables and data types2   variables and data types
2 variables and data typesTuan Ngo
 

Mais de Tuan Ngo (20)

Introduction of cg program for portal 20120424 en
Introduction of cg program for portal 20120424 enIntroduction of cg program for portal 20120424 en
Introduction of cg program for portal 20120424 en
 
Net framework
Net frameworkNet framework
Net framework
 
15 anonymous methods, partial types and nullable types
15   anonymous methods, partial types and nullable types15   anonymous methods, partial types and nullable types
15 anonymous methods, partial types and nullable types
 
14 generics and iterators
14   generics and iterators14   generics and iterators
14 generics and iterators
 
13 collections
13   collections13   collections
13 collections
 
11 exception handling
11   exception handling11   exception handling
11 exception handling
 
9 properties & indexers
9   properties & indexers9   properties & indexers
9 properties & indexers
 
10 namespace
10  namespace10  namespace
10 namespace
 
8 abstract classes and interfaces
8   abstract classes and interfaces 8   abstract classes and interfaces
8 abstract classes and interfaces
 
7 inheritance and polymorphism
7   inheritance and polymorphism7   inheritance and polymorphism
7 inheritance and polymorphism
 
5 arrays
5   arrays5   arrays
5 arrays
 
6 class and methods
6    class and methods6    class and methods
6 class and methods
 
3 statements and operators
3   statements and operators3   statements and operators
3 statements and operators
 
4 c# programming constructs
4   c# programming constructs4   c# programming constructs
4 c# programming constructs
 
1 get started with c#
1   get started with c#1   get started with c#
1 get started with c#
 
2 variables and data types
2   variables and data types2   variables and data types
2 variables and data types
 
Jdbc 7
Jdbc 7Jdbc 7
Jdbc 7
 
Jdbc 6
Jdbc 6Jdbc 6
Jdbc 6
 
Jdbc 3
Jdbc 3Jdbc 3
Jdbc 3
 
Jdbc 2
Jdbc 2Jdbc 2
Jdbc 2
 

Último

Mitochondrial Fusion Vital for Adult Brain Function and Disease Understanding...
Mitochondrial Fusion Vital for Adult Brain Function and Disease Understanding...Mitochondrial Fusion Vital for Adult Brain Function and Disease Understanding...
Mitochondrial Fusion Vital for Adult Brain Function and Disease Understanding...The Lifesciences Magazine
 
Political-Ideologies-and-The-Movements.pptx
Political-Ideologies-and-The-Movements.pptxPolitical-Ideologies-and-The-Movements.pptx
Political-Ideologies-and-The-Movements.pptxSasikiranMarri
 
12042024_First India Newspaper Jaipur.pdf
12042024_First India Newspaper Jaipur.pdf12042024_First India Newspaper Jaipur.pdf
12042024_First India Newspaper Jaipur.pdfFIRST INDIA
 
16042024_First India Newspaper Jaipur.pdf
16042024_First India Newspaper Jaipur.pdf16042024_First India Newspaper Jaipur.pdf
16042024_First India Newspaper Jaipur.pdfFIRST INDIA
 
Geostrategic significance of South Asian countries.ppt
Geostrategic significance of South Asian countries.pptGeostrategic significance of South Asian countries.ppt
Geostrategic significance of South Asian countries.pptUsmanKaran
 
13042024_First India Newspaper Jaipur.pdf
13042024_First India Newspaper Jaipur.pdf13042024_First India Newspaper Jaipur.pdf
13042024_First India Newspaper Jaipur.pdfFIRST INDIA
 
lok sabha Elections in india- 2024 .pptx
lok sabha Elections in india- 2024 .pptxlok sabha Elections in india- 2024 .pptx
lok sabha Elections in india- 2024 .pptxdigiyvbmrkt
 
11042024_First India Newspaper Jaipur.pdf
11042024_First India Newspaper Jaipur.pdf11042024_First India Newspaper Jaipur.pdf
11042024_First India Newspaper Jaipur.pdfFIRST INDIA
 
Emerging issues in migration policies.ppt
Emerging issues in migration policies.pptEmerging issues in migration policies.ppt
Emerging issues in migration policies.pptNandinituteja1
 
Power in International Relations (Pol 5)
Power in International Relations (Pol 5)Power in International Relations (Pol 5)
Power in International Relations (Pol 5)ssuser583c35
 
15042024_First India Newspaper Jaipur.pdf
15042024_First India Newspaper Jaipur.pdf15042024_First India Newspaper Jaipur.pdf
15042024_First India Newspaper Jaipur.pdfFIRST INDIA
 

Último (12)

Mitochondrial Fusion Vital for Adult Brain Function and Disease Understanding...
Mitochondrial Fusion Vital for Adult Brain Function and Disease Understanding...Mitochondrial Fusion Vital for Adult Brain Function and Disease Understanding...
Mitochondrial Fusion Vital for Adult Brain Function and Disease Understanding...
 
Political-Ideologies-and-The-Movements.pptx
Political-Ideologies-and-The-Movements.pptxPolitical-Ideologies-and-The-Movements.pptx
Political-Ideologies-and-The-Movements.pptx
 
World Economic Forum : The Global Risks Report 2024
World Economic Forum : The Global Risks Report 2024World Economic Forum : The Global Risks Report 2024
World Economic Forum : The Global Risks Report 2024
 
12042024_First India Newspaper Jaipur.pdf
12042024_First India Newspaper Jaipur.pdf12042024_First India Newspaper Jaipur.pdf
12042024_First India Newspaper Jaipur.pdf
 
16042024_First India Newspaper Jaipur.pdf
16042024_First India Newspaper Jaipur.pdf16042024_First India Newspaper Jaipur.pdf
16042024_First India Newspaper Jaipur.pdf
 
Geostrategic significance of South Asian countries.ppt
Geostrategic significance of South Asian countries.pptGeostrategic significance of South Asian countries.ppt
Geostrategic significance of South Asian countries.ppt
 
13042024_First India Newspaper Jaipur.pdf
13042024_First India Newspaper Jaipur.pdf13042024_First India Newspaper Jaipur.pdf
13042024_First India Newspaper Jaipur.pdf
 
lok sabha Elections in india- 2024 .pptx
lok sabha Elections in india- 2024 .pptxlok sabha Elections in india- 2024 .pptx
lok sabha Elections in india- 2024 .pptx
 
11042024_First India Newspaper Jaipur.pdf
11042024_First India Newspaper Jaipur.pdf11042024_First India Newspaper Jaipur.pdf
11042024_First India Newspaper Jaipur.pdf
 
Emerging issues in migration policies.ppt
Emerging issues in migration policies.pptEmerging issues in migration policies.ppt
Emerging issues in migration policies.ppt
 
Power in International Relations (Pol 5)
Power in International Relations (Pol 5)Power in International Relations (Pol 5)
Power in International Relations (Pol 5)
 
15042024_First India Newspaper Jaipur.pdf
15042024_First India Newspaper Jaipur.pdf15042024_First India Newspaper Jaipur.pdf
15042024_First India Newspaper Jaipur.pdf
 

12 events and delegates

  • 1. Events and Delegates Programming in C# tnngo2@gmail.com
  • 3. Delegates are objects that contain references to method that need to be invoked instead of containing the actual method names. call any method, which is identified only at runtime. to associate a delegate with a particular method, the method must have the same return type and parameter type as that of the delegate.
  • 4. 1. Declaring delegates 2. Create the method to be referenced 3. Instantiating delegates 4. Call https://gist.github.com/2427445
  • 7. Events a way for a class to provide notifications to clients of that class when some interesting thing happens to an object.
  • 8. Implement Events 1. Define a public delegate for the event 2. Create the event using the delegate 3. Subscribe to listen and handle the event 4. Raise the event https://gist.github.com/2427324