what is delegate:- A delegate is like a pointer to a function. It is a reference type data type and it holds the reference of a method. All the delegates are implicitly derived from System.Delegate class. A function can have one or more parameters of different data types, but to pass a function as a parameter, delegate is used Syntax:- A delegate can be declared using delegate keyword followed by a function signature as shown below. Delegate Syntax: <access modifier> delegate <return type> <delegate_name>(<parameters>) E.g:- public delegate void Print( int value ); Example: C# delegate class Program { // declare delegate public delegate void Print( int value ); static void Main( string [] args) { // Print delegate points to PrintNumber Print printDel = PrintNumber; // or // Print printDel = new
Posts
Showing posts from March, 2019