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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T19:57:12+00:00 2026-06-18T19:57:12+00:00

In The C# Programming language Bill Wagner says: Many people confuse dynamic binding with

  • 0

In The C# Programming language Bill Wagner says:

Many people confuse dynamic binding with type inference. Type
inference is statically bound. The compiler determines the type at
compile time. For example:

var i = 5;             //i is an int (Compiler performs type inference)
Console.WriteLine(i);  //Static binding to Console.WriteLine(int)

The compiler infers that i is an integer. All binding on the variable
i uses static binding.

Now, given this information and my own made-up dynamic scenerio:

        dynamic i = 5;       //Compiler punts
        Console.WriteLine(i);//This is now dynamically bound

We know type inference is statically bound. This implies that there is no way a dynamic variable can use type inference to determine a type. How does a dynamic type get resolved without using type inference?

Update
To try and clarify…at runtime we must somehow figure out what type i is right? Because I assign a literal 5 then the runtime can infer that i is an int. Isn’t that type inference rather than dynamic binding?

  • 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-18T19:57:13+00:00Added an answer on June 18, 2026 at 7:57 pm

    What distinction is Bill making?

    The distinction that Bill is making is that many people think that:

    var x = Whatever();
    x.Foo();
    

    will work out at runtime what method Foo to call based on the type of object returned at runtime by Whatever. That’s not true; that would be

    dynamic x = Whatever();
    x.Foo();
    

    The var just means "work out the type at compile time and substitute it in", not "work it out at runtime".

    So if I have

    dynamic i = 5;
    Console.WriteLine(i);
    

    What happens?

    The compiler generates code that is morally like this:

    object i = (object)5;
    DynamicCallSite callSite = new DynamicCallSite(typeof(Console), "WriteLine"));
    callSite.Invoke(i);
    

    It is a bit more complicated than that; the call site is cached, for one thing. But this gives you the flavour of it.

    The invocation method asks i for its type via GetType and then starts up a special version of the C# compiler that can understand reflection objects. It does overload resolution on the members of Console named WriteLine, and determines which overload of Console.WriteLine would have been called had i been typed as int in the first place.

    It then generates an expression tree representing that call, compiles the expression tree into a delegate, caches it in the call site, and invokes the delegate.

    The second time you do this, the cached call site looks in its cache and sees that the last time that i was int, a particular delegate was invoked. So the second time it skips creating the call site and doing overload resolution, and just invokes the delegate.

    For more information, see:

    http://ericlippert.com/2012/10/22/a-method-group-of-one/

    http://ericlippert.com/2012/11/05/dynamic-contagion-part-one/

    http://ericlippert.com/2012/11/09/dynamic-contagion-part-two/

    A historical perspective on the feature can be obtained from Chris and Sam’s blogs:

    http://blogs.msdn.com/b/cburrows/archive/tags/dynamic/

    http://blogs.msdn.com/b/samng/archive/tags/dynamic/

    They did a lot of the implementation; however some of these article reflect outdated design choices. We never did go with "The Phantom Method" algorithm, regrettably. (Not a great algorithm, but a great name!)

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

Sidebar

Related Questions

When a programming language is statically typed, the compiler can be more precise about
Wikipedia says: A programming language is a machine-readable artificial language designed to express computations
Is there any programming language (or type system) in which you could express the
programming language: C platform: ARM Compiler: ADS 1.2 I need to keep track of
In the Ruby Programming Language , Chapter 6 (second paragraph) they state: Many languages
From The C Programming Language (Brian W. Kernighan), 2.7 TYPE CONVERSIONS, pg 43 :
Many programming language runtime environments use stacks as their primary storage structure (e.g. see
A programming Language only 79kb in size. GWBASIC programming language confuse me, i download
Not so much a programming language... I'm building a website with many jQuery Ajax
In the R programming language, how do I get a dynamic array ( as

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.