Back to Browse

Delegates in C# with Examples | CSharp Delegates | Dot Net Tutorials

1.4K views
Sep 24, 2022
44:50

Delegates in C# with Examples | CSharp Delegates | Dot Net Tutorials In this video, I am going to discuss Delegates in C# with Examples. At the end of this video, you will understand Delegates in C#. What are Delegates in C#? In simple words, we can say that the delegates in C# are the Type-Safe Function Pointer. It means they hold the reference of a method or function and then call that method for execution. How to Invoke Methods using Delegates in C#? If you want to invoke or call a method using delegates, then you need to follow the following three steps. 2. Declare a Delegate 3. Instantiating a Delegate 4. Invoking a Delegate Rules of using Delegates in C#: 1. A delegate in C# is a user-defined type and hence before invoking a method using a delegate, we must have to define that delegate first. 2. The signature of the delegate must match the signature of the method, the delegate points to otherwise we will get a compiler error. This is the reason why delegates are called type-safe function pointers. What are the Types of Delegates in C#? The Delegates in C# are classified into two types as 1. Single Cast Delegate: If a delegate is used for invoking a single method, then it is called a single cast delegate or unicast delegate. In other words, we can say that the delegates that represent only a single function are known as single cast delegates. 2. Multicast Delegate: If a delegate is used for invoking multiple methods, then it is known as the multicast delegate. Or the delegates that represent more than one function are called Multicast delegates. Where do we use Delegates in C#? Delegates are used in the following cases: 1. Event Handlers 2. Callbacks 3. Passing Methods as Method Parameters 4. LINQ 5. Multithreading How many ways we can call a method in C#? In C#, we can call a method that is defined in a class in two ways. They are as follows: 1. We can call the method using the object of the class if it is a non-static method or we can call the method through the class name if it is a static method. 2. We can also call a method in C# by using delegates. Calling a C# method using delegate will be faster in execution as compared to the first process i.e. either by using an object or by using the class name. The text document of this video: https://dotnettutorials.net/lesson/delegates-csharp/ #delegates #csharpdelegates #delegatescsharpexamples #dotnettutorials #csharptutorials #csharpdelegatesexamples Delegates Delegates in C# Delegates in C# with Examples Delegates in CSharp Delegates in CSharp with Examples C# Delegates C# Delegates Examples C# Delegates with Examples CSharp Delegates CSharp Delegates Examples CSharp Delegates with Examples What are Delegates in C#? How to Invoke Methods using Delegates in C#? Where do we use Delegates in C#?

Download

1 formats

Video Formats

360pmp472.8 MB

Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.

Delegates in C# with Examples | CSharp Delegates | Dot Net Tutorials | NatokHD