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 8084645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:51:34+00:00 2026-06-05T17:51:34+00:00

From MSDN doc : A delegate is a type that safely encapsulates a method,

  • 0

From MSDN doc:

A delegate is a type that safely encapsulates a method, similar to a
function pointer in C and C++. Unlike C function pointers, delegates
are object-oriented, type safe, and secure.

I know what it is and how to use it. But I wonder whether or not it is written base on delegate pattern that I know (from wikipedia) .
What is the difference between them?

  • 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-06-05T17:51:36+00:00Added an answer on June 5, 2026 at 5:51 pm

    The C# (not the pattern) delegate might be useful when you are implementing the delegate pattern just look at this delegate pattern implementation from wikipedia with my changes:

    //NOTE: this is just a sample, not a suggestion to do it in such way
    
    public interface I
    {
        void F();
        void G();
    }
    
    public static class A
    {
        public static void F() { System.Console.WriteLine("A: doing F()"); }
        public static void G() { System.Console.WriteLine("A: doing G()"); }
    }
    
    public static class B
    {
        public static void F() { System.Console.WriteLine("B: doing F()"); }
        public static void G() { System.Console.WriteLine("B: doing G()"); }
    }
    
    public class C : I
    {
        // delegation 
        Action iF = A.F;
        Action iG = A.G;
    
        public void F() { iF(); }
        public void G() { iG(); }
    
        // normal attributes
        public void ToA() { iF = A.F; iG = A.G; }
        public void ToB() { iF = B.F; iG = B.G; }
    }
    
    public class Program
    {
        public static void Main()
        {
            C c = new C();
            c.F();     // output: A: doing F()
            c.G();     // output: A: doing G()
            c.ToB();
            c.F();     // output: B: doing F()
            c.G();     // output: B: doing G()
        }
    }
    

    Again delegate might be useful here, but it isn’t for it was introduced. You should look at it like on the low-level construction rather then the pattern. In the pair with the events it could be used to implement publisher/subscriber(observer) pattern – just look at this article, or it could sometimes help you to implement visitor pattern – this is actively used in the LINQ:

    public void Linq1() 
    { 
        int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 }; 
    
        // n => n < 5 is lambda function, creates a delegate here
        var lowNums = numbers.Where(n => n < 5); 
    
        Console.WriteLine("Numbers < 5:"); 
        foreach (var x in lowNums) 
        { 
            Console.WriteLine(x); 
        } 
    } 
    

    To summarize: a language delegate is not the pattern itself, it just allows you to operate functions as the first class objects.

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

Sidebar

Related Questions

From MSDN : Any method that matches the delegate's signature, which consists of the
From MSDN Types that implement IComparable must override Equals.Types that override Equals must also
From MSDN ( link ): The type PrintDocumentImageableArea has no public constructor. Hence, the
Why in this example from MSDN, in GetEnumerator method, PeopleEnum returns IEnumerator ? public
From MSDN's entry on Dictionary.TryGetValue Method : This method combines the functionality of the
[CrossPost From MSDN] I had a task that, I need to send a generic
This is from MSDN: The lock keyword ensures that one thread does not enter
Msdn doc for IsolatedStorageFile.IncreaseQuotaTo states that: To increase the quota, you must call this
From MSDN, it seems that Application.DoEvents() is available in Windows.Forms. What would be the
I copy code from MSDN It says that In Visual C++ 2005, the compiler

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.