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

  • Home
  • SEARCH
  • 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 7078729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:35:00+00:00 2026-05-28T06:35:00+00:00

I am wondering why the output of the given code (execute it in LinqPad)

  • 0

I am wondering why the output of the given code (execute it in LinqPad)

void Main() {
    Compare1((Action)Main).Dump();
    Compare2(Main).Dump();
}

bool Compare1(Delegate x) {
    return x == (Action)Main;
}

bool Compare2(Action x) {
    return x == Main;
}

is always:

 False
 True

I have naively expected it to be True in both cases.

  • 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-28T06:35:01+00:00Added an answer on May 28, 2026 at 6:35 am

    This is how it looks when compiled to IL and then decompiled back to C#. Note that in both cases there’s new Action(Main) – a new reference object (delegate) with pointer to actual method stored inside.

    private static void Main()
    {
        Program.Compare1(new Action(Program.Main)).Dump();
        Program.Compare2(new Action(Program.Main)).Dump();
        Console.ReadLine();
    }
    
    private static bool Compare1(Delegate x)
    {
       return x == new Action(Program.Main);
    }
    
    private static bool Compare2(Action x)
    {
       return x == new Action(Program.Main);
    }
    

    If then we take a look into CIL, the former uses ceq (reference comparison) and the latter uses call bool [mscorlib]System.Delegate::op_Equality(class [mscorlib]System.Delegate, class [mscorlib]System.Delegate) to compare delegates.

    First returns false because actions wrapping your delegates are two distinct reference objects.

    Second returns true as the equality operator implemented on the Delegate class compares actual targets inside wrappers (actions).

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

Sidebar

Related Questions

I'm wondering if there is a quick and easy way to output ordinals given
I am very new to C++ and I am wondering how you output/write variables
I'm just wondering what is an ideal output format for the AJAX response? Pure
I was just wondering if it is possible to capture the output of a
I have an array of output from a database. I am wondering what the
I'm wondering why these two following conditions in SQL return different results First Condition
I am wondering if there is a tool or technique which, given a BNF
Possible Duplicate: Addition of two chars produces int Given the following C++ code: unsigned
I have the following code in VS2008: int i,j; bool pr = false; #pragma
Wondering what would be quicker for a mysql open, select, and a generic output

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.