SlideShare a Scribd company logo
1 of 10
C# Tutorial
Part 30 :Delegation
www.siri-kt.blogspot.com
• In C#, delegate is a reference to the method. It works
like function pointer in C and C++. But it is objected-
oriented, secured and type-safe than function pointer.
• For static method, delegate encapsulates method only. But
for instance method, it encapsulates method and instance
both.
• delegates stores the address of one or many functions
delegates hides the actual information.
• The best use of delegate is to use as event.
• Internally a delegate declaration defines a class which is the
derived class of System.Delegate.
• note:
• What is Delegates in C # Delegate is the special type use
to hold the reference of function ,Delegate concept match
the function pointer concept of c language
• C# delegates are similar to pointers to functions, in C or C++.
A delegate is a reference type variable that holds the
reference to a method. The reference can be changed at
runtime.
• Delegates are especially used for implementing events and
the call-back methods. All delegates are implicitly derived
from the System.Delegate class.
• Declaring Delegates
• Delegate declaration determines the methods that can be
referenced by the delegate. A delegate can refer to a
method, which has the same signature as that of the
delegate.
• For example, consider a delegate:
• public delegate int MyDelegate (string s);The preceding
delegate can be used to reference any method that has a
singlestring parameter and returns an int type variable.
• Syntax for delegate declaration is:
• Delegate <return type> <delegate-name> <parameter
list>Instantiating Delegates
• Once a delegate type is declared, a delegate object must be
created with thenew keyword and be associated with a
particular method.
• When creating a delegate, the argument passed to
the new expression is written similar to a method call, but
without the arguments to the method. For example:
• public delegate void printString(string s); ... printString ps1 =
new printString(WriteToScreen); printString ps2 = new
printString(WriteToFile);
• Following example demonstrates declaration, instantiation,
and use of a delegate that can be used to reference methods
that take an integer parameter and returns an integer value.
• Delegates are classified into 2 types
• 1.single cast delegate
• 2.multi cast delegate
• Here we can follow 4 steps to create a delegate
• 1.write a class with methods
• 2.create a delegate
• syntax: public delegate void dname();
• 3.stores the address of method
• dname d=new dname(stores fn address);
• 4.call the delegate variable
• d();
• 1.single cast delegate:
• The single cast delegate holds only one function address. depending on the function
prototype we have to declare delegate. in each delegate instance variable we can
stores one function address.
• example on single cast delegate example:
• using System;
• namespace ConsoleApplication21
• { class test//class
• { public void print()//method
• { Console.WriteLine("helloworld");
• Console.ReadLine(); }
• public delegate void dname();//declare delegate
• static void Main(string[] args)
• { test obj = new test();//object
• // obj.print();
• dname d = new dname(obj.print);//stores the fn address
• d();//call the delegate varibale
• } } }
• Multi cast delegate :
It holds the address of more than one function also. multi cast delegate supports
arithmatic + and – operations + operator is used to add a function into the sequence.
• - operator is used to Remove a function from the sequence.
• example on multi cast delegate:
• using System;
• using System.Collections.Generic;
• using System.Linq;
• using System.Text;
• using System.Threading.Tasks;
• namespace multicastdelegateexample
• { class emp//class name
• { public void esal()//method1
• { Console.WriteLine("from esal");
• Console.ReadLine(); }
• public void tsal()//method1
• { Console.WriteLine("from tsal");
• Console.ReadLine(); }
• Multicasting of a Delegate
• Delegate objects can be composed using the "+"
operator. A composed delegate calls the two
delegates it was composed from. Only delegates of
the same type can be composed.
• The "-" operator can be used to remove a
component delegate from a composed delegate.
• Using this property of delegates you can create an
invocation list of methods that will be called when a
delegate is invoked. This is called multicasting of a
delegate.
• public delegate void dname();//declare delagate
• static void Main(string[] args)
• { emp obj = new emp();//object
• dname d1 = new dname(obj.esal);//stores fn1 address
• // d1();
• dname d2 = new dname(obj.tsal);//stores fn2
address
• // d2();
• dname d3;
• // d3 = d1 - d2;
• d3 = d1 + d2;//multi cast delegate
• d3();//call the delegate variable
• } } }
For more visit our website www.siri-kt.blogspot.com
Thanks for
Watching
More Angular JS TutorialsMore C sharp (c#) tutorials

More Related Content

What's hot (20)

Filehandling
FilehandlingFilehandling
Filehandling
 
Basic i/o & file handling in java
Basic i/o & file handling in javaBasic i/o & file handling in java
Basic i/o & file handling in java
 
Files in java
Files in javaFiles in java
Files in java
 
File handling in vb.net
File handling in vb.netFile handling in vb.net
File handling in vb.net
 
Java Tutorial Lab 6
Java Tutorial Lab 6Java Tutorial Lab 6
Java Tutorial Lab 6
 
Input output streams
Input output streamsInput output streams
Input output streams
 
9 Inputs & Outputs
9 Inputs & Outputs9 Inputs & Outputs
9 Inputs & Outputs
 
C# File IO Operations
C# File IO OperationsC# File IO Operations
C# File IO Operations
 
input/ output in java
input/ output  in javainput/ output  in java
input/ output in java
 
Java Tutorial Lab 4
Java Tutorial Lab 4Java Tutorial Lab 4
Java Tutorial Lab 4
 
Files and streams
Files and streamsFiles and streams
Files and streams
 
Java IO Package and Streams
Java IO Package and StreamsJava IO Package and Streams
Java IO Package and Streams
 
Java Tutorial Lab 1
Java Tutorial Lab 1Java Tutorial Lab 1
Java Tutorial Lab 1
 
Javaiostream
JavaiostreamJavaiostream
Javaiostream
 
Data file handling
Data file handlingData file handling
Data file handling
 
Byte stream classes.49
Byte stream classes.49Byte stream classes.49
Byte stream classes.49
 
CSV File Manipulation
CSV File ManipulationCSV File Manipulation
CSV File Manipulation
 
Filehandling
FilehandlingFilehandling
Filehandling
 
Io streams
Io streamsIo streams
Io streams
 
C++ Files and Streams
C++ Files and Streams C++ Files and Streams
C++ Files and Streams
 

Similar to 30csharp

Explain Delegates step by step.
Explain Delegates step by step.Explain Delegates step by step.
Explain Delegates step by step.Questpond
 
Presentation 4th
Presentation 4thPresentation 4th
Presentation 4thConnex
 
Learn c++ Programming Language
Learn c++ Programming LanguageLearn c++ Programming Language
Learn c++ Programming LanguageSteve Johnson
 
C programming language tutorial
C programming language tutorialC programming language tutorial
C programming language tutorialSURBHI SAROHA
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rdConnex
 
Introduction to c first week slides
Introduction to c first week slidesIntroduction to c first week slides
Introduction to c first week slidesluqman bawany
 
TypeScript: Basic Features and Compilation Guide
TypeScript: Basic Features and Compilation GuideTypeScript: Basic Features and Compilation Guide
TypeScript: Basic Features and Compilation GuideNascenia IT
 
Data Structures and Algorithms in Python
Data Structures and Algorithms in PythonData Structures and Algorithms in Python
Data Structures and Algorithms in PythonJakeLWright
 
Review of c_sharp2_features_part_ii
Review of c_sharp2_features_part_iiReview of c_sharp2_features_part_ii
Review of c_sharp2_features_part_iiNico Ludwig
 
Programming Language
Programming  LanguageProgramming  Language
Programming LanguageAdeel Hamid
 
Objective-C for iOS Application Development
Objective-C for iOS Application DevelopmentObjective-C for iOS Application Development
Objective-C for iOS Application DevelopmentDhaval Kaneria
 
C++ - Constructors,Destructors, Operator overloading and Type conversion
C++ - Constructors,Destructors, Operator overloading and Type conversionC++ - Constructors,Destructors, Operator overloading and Type conversion
C++ - Constructors,Destructors, Operator overloading and Type conversionHashni T
 

Similar to 30csharp (20)

Delegates and events
Delegates and events   Delegates and events
Delegates and events
 
Delegetes in c#
Delegetes in c#Delegetes in c#
Delegetes in c#
 
Explain Delegates step by step.
Explain Delegates step by step.Explain Delegates step by step.
Explain Delegates step by step.
 
Presentation 4th
Presentation 4thPresentation 4th
Presentation 4th
 
Learn c++ Programming Language
Learn c++ Programming LanguageLearn c++ Programming Language
Learn c++ Programming Language
 
C programming language tutorial
C programming language tutorialC programming language tutorial
C programming language tutorial
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rd
 
Introduction to c first week slides
Introduction to c first week slidesIntroduction to c first week slides
Introduction to c first week slides
 
c++ UNIT II.pptx
c++ UNIT II.pptxc++ UNIT II.pptx
c++ UNIT II.pptx
 
TypeScript: Basic Features and Compilation Guide
TypeScript: Basic Features and Compilation GuideTypeScript: Basic Features and Compilation Guide
TypeScript: Basic Features and Compilation Guide
 
Data Structures and Algorithms in Python
Data Structures and Algorithms in PythonData Structures and Algorithms in Python
Data Structures and Algorithms in Python
 
Review of c_sharp2_features_part_ii
Review of c_sharp2_features_part_iiReview of c_sharp2_features_part_ii
Review of c_sharp2_features_part_ii
 
Programming Language
Programming  LanguageProgramming  Language
Programming Language
 
c++ Unit III - PPT.pptx
c++ Unit III - PPT.pptxc++ Unit III - PPT.pptx
c++ Unit III - PPT.pptx
 
Introduction to C ++.pptx
Introduction to C ++.pptxIntroduction to C ++.pptx
Introduction to C ++.pptx
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Objective-C for iOS Application Development
Objective-C for iOS Application DevelopmentObjective-C for iOS Application Development
Objective-C for iOS Application Development
 
Java
JavaJava
Java
 
Data structure Unit-I Part A
Data structure Unit-I Part AData structure Unit-I Part A
Data structure Unit-I Part A
 
C++ - Constructors,Destructors, Operator overloading and Type conversion
C++ - Constructors,Destructors, Operator overloading and Type conversionC++ - Constructors,Destructors, Operator overloading and Type conversion
C++ - Constructors,Destructors, Operator overloading and Type conversion
 

More from Sireesh K (20)

Cn10
Cn10Cn10
Cn10
 
chanakya neeti
chanakya neetichanakya neeti
chanakya neeti
 
chanakya neeti
chanakya neetichanakya neeti
chanakya neeti
 
What is mvc
What is mvcWhat is mvc
What is mvc
 
31c
31c31c
31c
 
45c
45c45c
45c
 
44c
44c44c
44c
 
43c
43c43c
43c
 
42c
42c42c
42c
 
41c
41c41c
41c
 
40c
40c40c
40c
 
39c
39c39c
39c
 
38c
38c38c
38c
 
37c
37c37c
37c
 
35c
35c35c
35c
 
34c
34c34c
34c
 
33c
33c33c
33c
 
30c
30c30c
30c
 
29c
29c29c
29c
 
27c
27c27c
27c
 

Recently uploaded

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 

Recently uploaded (20)

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 

30csharp

  • 1. C# Tutorial Part 30 :Delegation www.siri-kt.blogspot.com
  • 2. • In C#, delegate is a reference to the method. It works like function pointer in C and C++. But it is objected- oriented, secured and type-safe than function pointer. • For static method, delegate encapsulates method only. But for instance method, it encapsulates method and instance both. • delegates stores the address of one or many functions delegates hides the actual information. • The best use of delegate is to use as event. • Internally a delegate declaration defines a class which is the derived class of System.Delegate. • note: • What is Delegates in C # Delegate is the special type use to hold the reference of function ,Delegate concept match the function pointer concept of c language
  • 3. • C# delegates are similar to pointers to functions, in C or C++. A delegate is a reference type variable that holds the reference to a method. The reference can be changed at runtime. • Delegates are especially used for implementing events and the call-back methods. All delegates are implicitly derived from the System.Delegate class. • Declaring Delegates • Delegate declaration determines the methods that can be referenced by the delegate. A delegate can refer to a method, which has the same signature as that of the delegate. • For example, consider a delegate: • public delegate int MyDelegate (string s);The preceding delegate can be used to reference any method that has a singlestring parameter and returns an int type variable.
  • 4. • Syntax for delegate declaration is: • Delegate <return type> <delegate-name> <parameter list>Instantiating Delegates • Once a delegate type is declared, a delegate object must be created with thenew keyword and be associated with a particular method. • When creating a delegate, the argument passed to the new expression is written similar to a method call, but without the arguments to the method. For example: • public delegate void printString(string s); ... printString ps1 = new printString(WriteToScreen); printString ps2 = new printString(WriteToFile); • Following example demonstrates declaration, instantiation, and use of a delegate that can be used to reference methods that take an integer parameter and returns an integer value.
  • 5. • Delegates are classified into 2 types • 1.single cast delegate • 2.multi cast delegate • Here we can follow 4 steps to create a delegate • 1.write a class with methods • 2.create a delegate • syntax: public delegate void dname(); • 3.stores the address of method • dname d=new dname(stores fn address); • 4.call the delegate variable • d();
  • 6. • 1.single cast delegate: • The single cast delegate holds only one function address. depending on the function prototype we have to declare delegate. in each delegate instance variable we can stores one function address. • example on single cast delegate example: • using System; • namespace ConsoleApplication21 • { class test//class • { public void print()//method • { Console.WriteLine("helloworld"); • Console.ReadLine(); } • public delegate void dname();//declare delegate • static void Main(string[] args) • { test obj = new test();//object • // obj.print(); • dname d = new dname(obj.print);//stores the fn address • d();//call the delegate varibale • } } }
  • 7. • Multi cast delegate : It holds the address of more than one function also. multi cast delegate supports arithmatic + and – operations + operator is used to add a function into the sequence. • - operator is used to Remove a function from the sequence. • example on multi cast delegate: • using System; • using System.Collections.Generic; • using System.Linq; • using System.Text; • using System.Threading.Tasks; • namespace multicastdelegateexample • { class emp//class name • { public void esal()//method1 • { Console.WriteLine("from esal"); • Console.ReadLine(); } • public void tsal()//method1 • { Console.WriteLine("from tsal"); • Console.ReadLine(); }
  • 8. • Multicasting of a Delegate • Delegate objects can be composed using the "+" operator. A composed delegate calls the two delegates it was composed from. Only delegates of the same type can be composed. • The "-" operator can be used to remove a component delegate from a composed delegate. • Using this property of delegates you can create an invocation list of methods that will be called when a delegate is invoked. This is called multicasting of a delegate.
  • 9. • public delegate void dname();//declare delagate • static void Main(string[] args) • { emp obj = new emp();//object • dname d1 = new dname(obj.esal);//stores fn1 address • // d1(); • dname d2 = new dname(obj.tsal);//stores fn2 address • // d2(); • dname d3; • // d3 = d1 - d2; • d3 = d1 + d2;//multi cast delegate • d3();//call the delegate variable • } } }
  • 10. For more visit our website www.siri-kt.blogspot.com Thanks for Watching More Angular JS TutorialsMore C sharp (c#) tutorials