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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:23:02+00:00 2026-05-17T02:23:02+00:00

Does defining an instance as dynamic in C# mean: The compiler does not perform

  • 0

Does defining an instance as dynamic in C# mean:

  1. The compiler does not perform compile-time type checking, but run-time checking takes place like it always does for all instances.

  2. The compiler does not perform compile-time type checking, but run-time checking takes place, unlike with any other non-dynamic instances.

  3. Same as 2, and this comes with performance penalty (trivial? potentially significant?).

  • 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-17T02:23:03+00:00Added an answer on May 17, 2026 at 2:23 am

    The question is very confusing.

    Does defining an instance as dynamic in C# mean:

    By “defining an instance” do you mean “declaring a variable”?

    The compiler does not perform compile-time type checking, but run-time checking takes place like it always does for all instances.

    What do you mean by “run-time checking like it always does”? What run-time checking did you have in mind? Are you thinking of the checking performed by the IL verifier, or are you thinking of runtime type checks caused by casts, or what?

    Perhaps it would be best to simply explain what “dynamic” does.

    First off, dynamic is from the perspective of the compiler a type. From the perspective of the CLR, there is no such thing as dynamic; by the time the code actually runs, all instances of “dynamic” have been replaced with “object” in the generated code.

    The compiler treats expressions of type dynamic exactly as expressions of type object, except that all operations on the value of that expression are analyzed, compiled and executed at runtime based on the runtime type of the instance. The goal is that the code executed has the same semantics as if the compiler had known the runtime types at compile time.

    Your question seems to be about performance.

    The best way to answer performance questions is to try it and find out – what you should do if you need hard numbers is to write the code both ways, using dynamic and using known types, and then get out a stopwatch and compare the timings. That’s the only way to know.

    However, let’s consider the performance implications of some operations at an abstract level. Suppose you have:

    int x = 123;
    int y = 456;
    int z = x + y;
    

    Adding two integers takes about a billionth of a second on most hardware these days.

    What happens if we make it dynamic?

    dynamic x = 123;
    dynamic y = 456;
    dynamic z = x + y;
    

    Now what does this do at runtime? This boxes 123 and 456 into objects, which allocates memory on the heap and does some copies.

    Then it starts up the DLR and asks the DLR “has this code site been compiled once already with the types for x and y being int and int?”

    The answer in this case is no. The DLR then starts up a special version of the C# compiler which analyzes the addition expression, performs overload resolution, and spits out an expression tree describing the lambda which adds together two ints. The DLR then compiles that lambda into dynamically generated IL, which the jit compiler then jits. The DLR then caches that compiled state so that the second time you ask, the compiler doesn’t have to do all that work over again.

    That takes longer than a nanosecond. It takes potentially many thousands of nanoseconds.

    Does that answer your questions? I don’t really understand what you’re asking here but I’m making a best guess.

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

Sidebar

Related Questions

Why does defining __getitem__ on a class make it iterable? For instance if I
Does defining functions inside a loop affect performance? Like var doSomething = function(element){ $(element).whatever();
Possible Duplicate: Why does defining getitem on a class make it iterable in python?
Does anyone know of any tools capable of defining a declarative mapping from T-Box
I am defining @foo as a class instance attribute, and using the after_initialize callback
In C++, does defining additional methods or functions that don't get used result in
I'm wondering what does represent CASCADE when defining relations in InnoDB? I see it's
I wrote a storable vector instance for the data type below ( original question
What does _np suffix mean here: pthread_mutex_timedlock_np or in macros PTHREAD_MUTEX_TIMED_NP Upd: From glibc2.2
When defining classes, does R have any notion of private vs public slots? If

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.