Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7582801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:31:30+00:00 2026-05-30T18:31:30+00:00

Possible Duplicate: What are the advantages of delegates? I have created a sample application.

  • 0

Possible Duplicate:
What are the advantages of delegates?

I have created a sample application. I am really finding it difficult to understand why to use delegates because without delegates we can achieve everything .

class Program
{
    public delegate double Integrand(double x);
    static double MyFunc1(double x) { return x + 10; }
    static double MyFunc2(double x) { return x + 20; }

    public static double Gauss3DelMethod(Integrand f)
    {
        double a = f(1);
        return a;
    }

    public static double Gauss3SimpleMethod(double x)
    {
        double a = x;
        return a;
    }

    static void Main(string[] args)
    {
        //with delegates
        double res = Gauss3DelMethod(MyFunc1);
        double res1 = Gauss3DelMethod(MyFunc2);

        //without delegates
        double res2 = Gauss3SimpleMethod(MyFunc1(1));
        double res3 = Gauss3SimpleMethod(MyFunc2(1));

        int i = 0;
    }
}

So, why should I use delegates?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T18:31:32+00:00Added an answer on May 30, 2026 at 6:31 pm

    In your particular example, maybe it’s not important. (It’s not clear what it’s trying to achieve.)

    But suppose you wanted to make the method execute the same MyFunc1 or MyFunc2 for several different inputs. For example, suppose you were implementing the Newton-Raphson method, to operate over a general function. In that situation, you couldn’t call the function once and pass that into the method – you want to pass the actual function into the method, so that the method can call it with whatever inputs it needs.

    A similar example is sorting. For example, using LINQ you can write something like:

    var sorted = people.OrderBy(x => x.Age).ToList();
    

    There we’re passing a function to project each source element to the ordering key. We don’t have to execute that function ourselves – OrderBy will do it for us (lazily).

    Of course, all of this can be done with single-method interfaces too – delegates and single-method interfaces have a lot in common. However, delegates have the following benefits over single-method interfaces:

    • Delegates are multi-cast – they can be combined/removed, usually for the sake of events
    • You can execute them asynchronously with BeginInvoke/EndInvoke
    • You can build them with anonymous methods and lambda expressions
    • You can represent logic as data via expression trees using lambda expresions; these can then be compiled into delegates
    • You can build a delegate from any method with the appropriate signature – so for example a single class can have multiple methods “implementing” the same delegate type, whereas you can’t implement an interface multiple times in one class
    • Likewise delegate implementation methods can be private, whereas interface methods have to be public (or somewhat-public via explicit interface implementation)

    All of these could have been addressed differently using single-method interfaces, of course, but delegates are a handy alternative.

    In conclusion: delegates are very useful. Just because you’ve written some trivial code which doesn’t particularly require them doesn’t mean they’re not useful. I would strongly suggest you look into LINQ, event handlers and the TPL, all of which use delegates heavily.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: What Advantages of Extension Methods have you found? All right, first of
Possible Duplicate: Why should I use Google's CDN for jQuery? I have seen many
Possible Duplicate: Why not use tables for layout in HTML? Under what conditions should
Possible Duplicate: How does the Google Did you mean? Algorithm work? Suppose you have
Possible Duplicate: When to use static vs instantiated classes I'm having a little trouble
Possible Duplicate: Understanding Enums in Java Why should we use enums rather Java constants?
Possible Duplicate: Advantages of SQL Server 2008 over SQL Server 2005? What are the
Possible Duplicate: Advantages of std::for_each over for loop So I was playing around with
Possible Duplicate: B- trees, B+ trees difference What are the advantages/disadvantages of BTree+ over
Possible Duplicate: Are PHP short tags acceptable to use? <?=$num2?> $num2 is calling data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.