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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:49:16+00:00 2026-05-13T05:49:16+00:00

Possible Duplicate: What’s the difference between dynamic(C# 4) and var? What is the difference

  • 0

Possible Duplicate:
What’s the difference between dynamic(C# 4) and var?

What is the difference between dynamic and var keyword in .NET 4.0 (VS 2010). As per MSDN, the definition of dynamic is – Dynamic lookup allows you to write method, operator and indexer calls, property and field accesses, and even object invocations which bypass the normal static binding of C# and instead gets resolved dynamically.

Whereas the definition for var is – An implicitly typed local variable is strongly typed just as if you had declared the type yourself, but the compiler determines the type.

How is this different in the code context below:

var a1 = new A();
a1.Foo(1);

dynamic a2 = new A();
a2.Foo(1);
  • 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-13T05:49:16+00:00Added an answer on May 13, 2026 at 5:49 am

    var means the static type is inferred – in your case it’s exactly equivalent to

    A a1 = new A();
    

    All the binding is still done entirely statically. If you look at the generated code, it will be exactly the same as with the above declaration.

    dynamic means that all any expression using a2 is bound at execution time rather than at compile-time, so it can behave dynamically. The compiler won’t check whether the Foo method exists – the behaviour is determined at execution time. Indeed, if the object implements IDynamicMetaObjectProvider it could decide what to do with the call at execution time, responding to any method call (or other kind of use) – in other words, there doesn’t have to be a “real” method called Foo at all.

    If you look at the generated code in the dynamic situation, you’ll find all kinds of weird and wonderful stuff going on to do with call sites and binders.

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

Sidebar

Ask A Question

Stats

  • Questions 293k
  • Answers 293k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I see two questions What toolboxes are required for the… May 13, 2026 at 6:27 pm
  • Editorial Team
    Editorial Team added an answer We use #1 extensively and it works perfectly. You shouldn't… May 13, 2026 at 6:27 pm
  • Editorial Team
    Editorial Team added an answer I figured out how to limit their choices to one.… May 13, 2026 at 6:27 pm

Related Questions

Possible Duplicate: A clear, layman’s explanation of the difference between | and || in
Possible Duplicate: What’s the right way to overload operator== for a class hierarchy? In
Possible Duplicate: What’s with the love of dynamic Languages I have already read this
Possible Duplicate: Is JavaScript’s math broken? This seems really stupid, but when running this,
Possible Duplicate: When is JavaScript’s eval() not evil? I know, generally using eval() is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.