Interested in mastering .NET? Learn more about ".NET Training" in this blog post.
Step 1. Write a class with a method
Syntax:-
Class Test {
Public void Print ()
{
logic ;
}
}
Step 2. Create a Delegate
Syntax :- public delegate void D name ();
Step 3 . create an object for the delegate with the address of a method.
Syntax :-
Test t = new Test ()
D name d = new D name (t. print);
Step 4. Call the Delegate
Syntax :- d ();
Example on SCD :-
{
Class Test
{
Public void Print ()
{
Console .Write (“From Print”);
}
}
//test
Public delegate void D name ();
Code in main ()
Test t = new Test ();
D name d = new D name (t. print);
D();
Console. Read Line ();
OBS:-
Delegates encapsulate some information like class name and method names.
OBS:
D6= D5 – D3 – D2 = GM GA - GM GA - GA = GM
Class Test
{
Public void M1 ()
{
Console . Write (“GM ”);
}
//M1
Public void M2 ()
{
Console . Write Line (“GA”);
}
//M2
}
// Test
Public delegate void XYZ ();
Static void Main (Strings [] args)
Code in main ()
{
Test t = new Test ();
XYZ = d1, d2, d3,d4,d5,d6;
D1 = new XYZ (t. M1);
D2 = new XYZ (t.M2);
D3 = d1 + d2; Console. Write line (“From D3 :”);
D3 ();
D4 = d3 +d3;
Console. Write line (“From D4 :”);
D4 ();
D5 = d4- d1;
Console. Write line (“From D5:”); D5 ();
D6 =d5-d3-d2;
Console. Write line (“From D6 :”);
D6 ();
Console. Read line ();
}
You liked the article?
Like: 0
Vote for difficulty
Current difficulty (Avg): Medium
TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.