Find the best tutors and institutes for C# .NET

Find Best C# .NET

Please select a Category.

Please select a Locality.

No matching category found.

No matching Locality found.

Outside India?

Search for topics

Understanding Delegate in C# .NET

P K Subudhi
14/05/2017 0 0

C# Delegate technique

Delegate is one of the fantastic tool & technique in C#.NET. Using deleagte technique the following benefits could be avaialed

  • One can define a method without name (Anonymous Method)
  • One can pass a Method as argument to another Method
  • Can join (or Add) two or more non-returnable methods methods
  • Core to combine event and event actions

Here is a simple example that demonstrates how delegates are being used in C#

Delegate used with instance method, static method, general named method and Anonymous method

Delegate Example


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

public delegate int DelType(int n);

namespace DelDemo


    class Num


        int a;

        public Num() { a = 0; }

        public Num(int n) { a = n; }

        public void Disp() { Console.WriteLine("Data is " + a); }

        public int Power(int n) // Instance method


            int r = 1;

            while ( n> 0)


                r = r * a;



            return r;


        static public int Rev(int t) // Static method


            int r = 0;


            while (t > 0)


                r = (r * 10) + (t % 10);

                t = t / 10;


            return r;



    class Program


        static int Fact(int n) // Named method


            int f=1;


            return f;


        static void Main(string[] args)


            DelType act = delegate(int n)  //Anonymous method


                int s = 0;

                while (n > 0)


                    s = s + (n % 10);

                    n = n / 10;


                return s;


            Console.WriteLine("Sum of digit is "+act(234));

            Num p = new Num(5);

            act = Num.Rev;    // Using static method

            Console.WriteLine("Reverse number is " + act(567));

            act = Fact; // Using general named method

            Console.WriteLine("Factorial is " + act(5));

            act = p.Power; //Using instance method

            Console.WriteLine("Power is " + act(3));






0 Dislike
Follow 0

Please Enter a comment


Other Lessons for You

Facebook Analytics
Assume how the Facebook application will store the millions of customer's record in real-time: facebook = { 'jose': { 'name': 'jose', 'age': 33, 'hobby': , # cricket,football 'mobile': 1111111111, 'email':...

Logeswaran | 03/09/2019

0 0

Multi-core CPU utilization using Task Parallel Library in c#
Nowadays, we are using multiple core systems. We must write our .NET applications in such a way that we must utilise the complete computing power of the machine. The parallel task library(TPL) allows...

Ketan Agnihotri | 12/01/2019

0 0

Why a function in C# requires "Return type"??
- Basically , a Method is a piece of code used for the re-usability purpose. - Method is of 2 types Function and Procedure - Function is a method which returns a value to the calling place Function...

Raga Deepthi G. | 25/09/2018

0 0

What are various validator in ASP.NET 2.0 and features common in all validation control in ASP.NET
Control to validate an error message. Are common feature in all the controls.Various validators are requiredfeild validator ,compare validator ,regular expression validator,custom validator,range validator...

Suprio Dutta | 29/06/2018

0 0

What are Various Types of Exception in C#
ArgumentException, ArgumentNullException, and ArgumentOutOfRangeException. NullReferenceException, IndexOutOfRangeException, SQL exceptions Stack Overflow Exception, Invalid Castexception ArgumentException...

Suprio Dutta | 28/06/2018

0 0

Looking for C# .NET Classes?

Find best tutors for C# .NET Classes by posting a requirement.

  • Post a learning requirement
  • Get customized responses
  • Compare and select the best

Looking for C# .NET Classes?

Find best C# .NET Classes in your locality on UrbanPro

Post your learning requirement is India's largest network of most trusted tutors and institutes. Over 25 lakh students rely on, to fulfill their learning requirements across 1,000+ categories. Using, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 6.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more