SlideShare a Scribd company logo
DELEGATES
This presentation will explain
about delegates in
C#(Csharp).
 Delegate is defined as a pointer to a
function.
 A delegate is an object that can refer to a
method.
 Therefore , when you create a delegate
,you are creating an object that can hold
a reference to a method.
 The delegate declaration specifies a
return type and parameter list.
 A delegate can invoke the method to which it
refers. Thus, the method that will be invoked
by a delegate is not determined at compile
time , but rather at runtime. This is the
advantage of a delegate.
 You can then initialize the variable as a
reference to any function that has the same
return type and parameter list as that
delegate.
 Delegate is a communication channel, it helps
us to call back after getting the results.
The general form of delegate declaration
is shown here:-
Syntax:
public delegate ret-type
delegatename(parameter-list);
• ret-type is the type of value returned by the methods
that the delegate will be calling. The name of the
delegate is specified by name.
• The parameters required by the methods called
through the delegates are specified in the
parameter-list.
Uses of delegates:-
• Delegates allow methods to be passed as
parameters.
• Delegates can be used to define call back
methods.
• Delegates are used to pass methods as
arguments to other methods.
• Delegates are like function pointers where
input parameter and return parameter should
be same type.
Program:-
using System;
namespace ConsoleApplication1
{
public delegate int myDel(int a, int b)
class Program
{
static void MethodAdd(int a, int b)
{
int c= a+b;
return c;
}
static void Main(string[] args)
{
myDel obj= new myDel(MethodAdd);
int c= obj(10,6)
Console.Writeline(“addition of two no. is: “ +c);
Console.ReadKey();
}
}
}
Output:-
addition of two no. is: 16
Types of Delegates:
There are two types of delegate.
1. Single delegate:-
• A delegate is called simple delegate if it
invokes a single method.
• Simple delegate refer to a single method.
2. Multicast delegate:-
• The Multicast delegates can invoke multiple
methods.
• Multicast delegates can send messages to
multiple clients/subscribers
• It uses += sign to broadcast multiple clients.
• It makes two way communication.
Program:-
using System;
namespace ConsoleApplication2
{
public delegate int myDel(int a, int b)
class Program
{
static void MethodAdd(int a, int b)
{
Console.Writeline(“The sum is: “ + (a+b));
}
static void MethodMul(int a, int b)
{
Console.Writeline(“The product is: “ + (a*b) );
}
static void Main(string[] args)
{
myDel obj= new myDel(MethodAdd);
obj += new myDel(MethodMul);
Console.ReadKey();
}
}
}
Ad

More Related Content

What's hot (20)

PL/SQL TRIGGERS
PL/SQL TRIGGERSPL/SQL TRIGGERS
PL/SQL TRIGGERS
Lakshman Basnet
 
JDBC
JDBCJDBC
JDBC
People Strategists
 
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
Jaliya Udagedara
 
C# Arrays
C# ArraysC# Arrays
C# Arrays
Hock Leng PUAH
 
Java 8 Lambda and Streams
Java 8 Lambda and StreamsJava 8 Lambda and Streams
Java 8 Lambda and Streams
Venkata Naga Ravi
 
Pure virtual function and abstract class
Pure virtual function and abstract classPure virtual function and abstract class
Pure virtual function and abstract class
Amit Trivedi
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
Dr.Neeraj Kumar Pandey
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methods
Shubham Dwivedi
 
array of object pointer in c++
array of object pointer in c++array of object pointer in c++
array of object pointer in c++
Arpita Patel
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
Pavith Gunasekara
 
LINQ in C#
LINQ in C#LINQ in C#
LINQ in C#
Basant Medhat
 
Abstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core JavaAbstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core Java
MOHIT AGARWAL
 
Types of Constructor in C++
Types of Constructor in C++Types of Constructor in C++
Types of Constructor in C++
Bhavik Vashi
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
Vikas Jagtap
 
Access Modifier.pptx
Access Modifier.pptxAccess Modifier.pptx
Access Modifier.pptx
Margaret Mary
 
[OOP - Lec 07] Access Specifiers
[OOP - Lec 07] Access Specifiers[OOP - Lec 07] Access Specifiers
[OOP - Lec 07] Access Specifiers
Muhammad Hammad Waseem
 
Exception handling
Exception handlingException handling
Exception handling
PhD Research Scholar
 
Lambda Expressions in Java
Lambda Expressions in JavaLambda Expressions in Java
Lambda Expressions in Java
Erhan Bagdemir
 
Java 8 streams
Java 8 streamsJava 8 streams
Java 8 streams
Manav Prasad
 
Object Oriented Programming with C#
Object Oriented Programming with C#Object Oriented Programming with C#
Object Oriented Programming with C#
foreverredpb
 
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
Jaliya Udagedara
 
Pure virtual function and abstract class
Pure virtual function and abstract classPure virtual function and abstract class
Pure virtual function and abstract class
Amit Trivedi
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methods
Shubham Dwivedi
 
array of object pointer in c++
array of object pointer in c++array of object pointer in c++
array of object pointer in c++
Arpita Patel
 
Abstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core JavaAbstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core Java
MOHIT AGARWAL
 
Types of Constructor in C++
Types of Constructor in C++Types of Constructor in C++
Types of Constructor in C++
Bhavik Vashi
 
Access Modifier.pptx
Access Modifier.pptxAccess Modifier.pptx
Access Modifier.pptx
Margaret Mary
 
Lambda Expressions in Java
Lambda Expressions in JavaLambda Expressions in Java
Lambda Expressions in Java
Erhan Bagdemir
 
Object Oriented Programming with C#
Object Oriented Programming with C#Object Oriented Programming with C#
Object Oriented Programming with C#
foreverredpb
 

Similar to Explain Delegates step by step. (20)

30csharp
30csharp30csharp
30csharp
Sireesh K
 
30c
30c30c
30c
Sireesh K
 
Learn C# Programming - Encapsulation & Methods
Learn C# Programming - Encapsulation & MethodsLearn C# Programming - Encapsulation & Methods
Learn C# Programming - Encapsulation & Methods
Eng Teong Cheah
 
Class 10
Class 10Class 10
Class 10
SIVASHANKARIRAJAN
 
tutorials-c-sharp_understanding-generic-anonymous-methods-and-lambda-expressi...
tutorials-c-sharp_understanding-generic-anonymous-methods-and-lambda-expressi...tutorials-c-sharp_understanding-generic-anonymous-methods-and-lambda-expressi...
tutorials-c-sharp_understanding-generic-anonymous-methods-and-lambda-expressi...
Anil Sharma
 
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
vekariyakashyap
 
Function C programming
Function C programmingFunction C programming
Function C programming
Appili Vamsi Krishna
 
c & c++ logic building concepts practice.pptx
c & c++ logic building concepts practice.pptxc & c++ logic building concepts practice.pptx
c & c++ logic building concepts practice.pptx
rawatsatish0327
 
Functions in c language
Functions in c languageFunctions in c language
Functions in c language
Tanmay Modi
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
tanmaymodi4
 
C language 3
C language 3C language 3
C language 3
Arafat Bin Reza
 
java150929145120-lva1-app6892 (2).pptx
java150929145120-lva1-app6892 (2).pptxjava150929145120-lva1-app6892 (2).pptx
java150929145120-lva1-app6892 (2).pptx
BruceLee275640
 
PROGRAMMING USING C#.NET SARASWATHI RAMALINGAM
PROGRAMMING USING C#.NET SARASWATHI RAMALINGAMPROGRAMMING USING C#.NET SARASWATHI RAMALINGAM
PROGRAMMING USING C#.NET SARASWATHI RAMALINGAM
SaraswathiRamalingam
 
Funtions of c programming. the functions of c helps to clarify all the tops
Funtions of c programming. the functions of c helps to clarify all the topsFuntions of c programming. the functions of c helps to clarify all the tops
Funtions of c programming. the functions of c helps to clarify all the tops
sameermhr345
 
Delegate
DelegateDelegate
Delegate
abhay singh
 
Ap Power Point Chpt4
Ap Power Point Chpt4Ap Power Point Chpt4
Ap Power Point Chpt4
dplunkett
 
PSPC-UNIT-4.pdf
PSPC-UNIT-4.pdfPSPC-UNIT-4.pdf
PSPC-UNIT-4.pdf
ArshiniGubbala3
 
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Akhil Mittal
 
functions
functionsfunctions
functions
Itishree Soni
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
Pranali Chaudhari
 
Learn C# Programming - Encapsulation & Methods
Learn C# Programming - Encapsulation & MethodsLearn C# Programming - Encapsulation & Methods
Learn C# Programming - Encapsulation & Methods
Eng Teong Cheah
 
tutorials-c-sharp_understanding-generic-anonymous-methods-and-lambda-expressi...
tutorials-c-sharp_understanding-generic-anonymous-methods-and-lambda-expressi...tutorials-c-sharp_understanding-generic-anonymous-methods-and-lambda-expressi...
tutorials-c-sharp_understanding-generic-anonymous-methods-and-lambda-expressi...
Anil Sharma
 
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
vekariyakashyap
 
c & c++ logic building concepts practice.pptx
c & c++ logic building concepts practice.pptxc & c++ logic building concepts practice.pptx
c & c++ logic building concepts practice.pptx
rawatsatish0327
 
Functions in c language
Functions in c languageFunctions in c language
Functions in c language
Tanmay Modi
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
tanmaymodi4
 
java150929145120-lva1-app6892 (2).pptx
java150929145120-lva1-app6892 (2).pptxjava150929145120-lva1-app6892 (2).pptx
java150929145120-lva1-app6892 (2).pptx
BruceLee275640
 
PROGRAMMING USING C#.NET SARASWATHI RAMALINGAM
PROGRAMMING USING C#.NET SARASWATHI RAMALINGAMPROGRAMMING USING C#.NET SARASWATHI RAMALINGAM
PROGRAMMING USING C#.NET SARASWATHI RAMALINGAM
SaraswathiRamalingam
 
Funtions of c programming. the functions of c helps to clarify all the tops
Funtions of c programming. the functions of c helps to clarify all the topsFuntions of c programming. the functions of c helps to clarify all the tops
Funtions of c programming. the functions of c helps to clarify all the tops
sameermhr345
 
Ap Power Point Chpt4
Ap Power Point Chpt4Ap Power Point Chpt4
Ap Power Point Chpt4
dplunkett
 
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Akhil Mittal
 
Ad

More from Questpond (8)

Most asked JAVA Interview Questions & Answers.
Most asked JAVA Interview Questions & Answers.Most asked JAVA Interview Questions & Answers.
Most asked JAVA Interview Questions & Answers.
Questpond
 
30 C# Interview Questions and Answers
30 C# Interview Questions and Answers30 C# Interview Questions and Answers
30 C# Interview Questions and Answers
Questpond
 
OOP interview questions & answers.
OOP interview questions & answers.OOP interview questions & answers.
OOP interview questions & answers.
Questpond
 
AOT(Ahead Of Time)
AOT(Ahead Of Time)AOT(Ahead Of Time)
AOT(Ahead Of Time)
Questpond
 
What is CLS in .NET programming.
What is CLS in .NET programming.What is CLS in .NET programming.
What is CLS in .NET programming.
Questpond
 
Explain CTS in detail.
Explain CTS in detail. Explain CTS in detail.
Explain CTS in detail.
Questpond
 
Learn .NET step by step :- What is IL code in .NET?
Learn .NET step by step :- What is IL code in .NET?Learn .NET step by step :- What is IL code in .NET?
Learn .NET step by step :- What is IL code in .NET?
Questpond
 
What is Higher Language and Lower Language in programming.
What is Higher Language and Lower Language in programming.What is Higher Language and Lower Language in programming.
What is Higher Language and Lower Language in programming.
Questpond
 
Most asked JAVA Interview Questions & Answers.
Most asked JAVA Interview Questions & Answers.Most asked JAVA Interview Questions & Answers.
Most asked JAVA Interview Questions & Answers.
Questpond
 
30 C# Interview Questions and Answers
30 C# Interview Questions and Answers30 C# Interview Questions and Answers
30 C# Interview Questions and Answers
Questpond
 
OOP interview questions & answers.
OOP interview questions & answers.OOP interview questions & answers.
OOP interview questions & answers.
Questpond
 
AOT(Ahead Of Time)
AOT(Ahead Of Time)AOT(Ahead Of Time)
AOT(Ahead Of Time)
Questpond
 
What is CLS in .NET programming.
What is CLS in .NET programming.What is CLS in .NET programming.
What is CLS in .NET programming.
Questpond
 
Explain CTS in detail.
Explain CTS in detail. Explain CTS in detail.
Explain CTS in detail.
Questpond
 
Learn .NET step by step :- What is IL code in .NET?
Learn .NET step by step :- What is IL code in .NET?Learn .NET step by step :- What is IL code in .NET?
Learn .NET step by step :- What is IL code in .NET?
Questpond
 
What is Higher Language and Lower Language in programming.
What is Higher Language and Lower Language in programming.What is Higher Language and Lower Language in programming.
What is Higher Language and Lower Language in programming.
Questpond
 
Ad

Recently uploaded (20)

Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
Political History of Pala dynasty Pala Rulers NEP.pptx
Political History of Pala dynasty Pala Rulers NEP.pptxPolitical History of Pala dynasty Pala Rulers NEP.pptx
Political History of Pala dynasty Pala Rulers NEP.pptx
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Library Association of Ireland
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
Operations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdfOperations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdf
Arab Academy for Science, Technology and Maritime Transport
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Library Association of Ireland
 
P-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 finalP-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 final
bs22n2s
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Library Association of Ireland
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Library Association of Ireland
 
P-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 finalP-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 final
bs22n2s
 

Explain Delegates step by step.

  • 1. DELEGATES This presentation will explain about delegates in C#(Csharp).
  • 2.  Delegate is defined as a pointer to a function.  A delegate is an object that can refer to a method.  Therefore , when you create a delegate ,you are creating an object that can hold a reference to a method.  The delegate declaration specifies a return type and parameter list.
  • 3.  A delegate can invoke the method to which it refers. Thus, the method that will be invoked by a delegate is not determined at compile time , but rather at runtime. This is the advantage of a delegate.  You can then initialize the variable as a reference to any function that has the same return type and parameter list as that delegate.  Delegate is a communication channel, it helps us to call back after getting the results.
  • 4. The general form of delegate declaration is shown here:- Syntax: public delegate ret-type delegatename(parameter-list); • ret-type is the type of value returned by the methods that the delegate will be calling. The name of the delegate is specified by name. • The parameters required by the methods called through the delegates are specified in the parameter-list.
  • 5. Uses of delegates:- • Delegates allow methods to be passed as parameters. • Delegates can be used to define call back methods. • Delegates are used to pass methods as arguments to other methods. • Delegates are like function pointers where input parameter and return parameter should be same type.
  • 6. Program:- using System; namespace ConsoleApplication1 { public delegate int myDel(int a, int b) class Program { static void MethodAdd(int a, int b) { int c= a+b; return c; } static void Main(string[] args) { myDel obj= new myDel(MethodAdd); int c= obj(10,6) Console.Writeline(“addition of two no. is: “ +c); Console.ReadKey(); } } }
  • 7. Output:- addition of two no. is: 16 Types of Delegates: There are two types of delegate. 1. Single delegate:- • A delegate is called simple delegate if it invokes a single method. • Simple delegate refer to a single method.
  • 8. 2. Multicast delegate:- • The Multicast delegates can invoke multiple methods. • Multicast delegates can send messages to multiple clients/subscribers • It uses += sign to broadcast multiple clients. • It makes two way communication.
  • 9. Program:- using System; namespace ConsoleApplication2 { public delegate int myDel(int a, int b) class Program { static void MethodAdd(int a, int b) { Console.Writeline(“The sum is: “ + (a+b)); } static void MethodMul(int a, int b) { Console.Writeline(“The product is: “ + (a*b) ); } static void Main(string[] args) { myDel obj= new myDel(MethodAdd); obj += new myDel(MethodMul); Console.ReadKey(); } } }