What is delegates in c#?
Prem Murmu
on
2/23/2021 1:23:31 AM
A delegate represents references to methods with a particular parameter list and return type. delegate can be associate its instance with any method with a compatible signature and return type and able to invoke and call through the delegate.
Delegates are used to pass methods as arguments to other methods.
Example:
namespace delegatedemo
{
//declaring a delegate
public delegate void DelegateDemo(string msg);
class Program
{
static void Main(string[] args)
{
// set target method
DelegateDemo del = new DelegateDemo(MSG);
// or
DelegateDemo del1 = MSG;
// or set lambda expression
DelegateDemo del2 = (string msg) =>
Console.WriteLine(msg);
// target method
static void MSG(string message)
{
Console.WriteLine(message);
}
}
}
0 Comments on this post
Comments(0)||Login to Comments
- see more..
Categories
ALLAsp.Net (3)
Sitecore (11)
Issues Resolved (9)
Sitecore 9.3 (2)
International Business (1)
Innovations in Industries (3)
Supply Chain Management (1)
Industrial Engineering (14)
Sitecore 10 (4)
Sharepoint (1)
Azure (4)
Cloud Computing (1)
Online Courses (1)
Online Resources (2)
C# (1)
Blazor WebAssembly (2)
Sitecore form (1)
MS Sql Server (1)
Angular 11 (2)
Automobile Engineering (5)
Sitecore powershell (1)
Devops (2)
Microservice Architecture (1)
Sitecore Interview Questions (2)
Dotnet interview questions (1)
Sitecore useful links (1)
Privacy&Cookies (2)
Solr Search (2)
JavaScript (1)
sitecore xm cloud (3)