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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:26:58+00:00 2026-05-13T18:26:58+00:00

I think I have my brain halfway wrapped around the Dynamic Types concept in

  • 0

I think I have my brain halfway wrapped around the Dynamic Types concept in C# 4, but can’t for the life of me figure out a scenario where I’d actually want to use it.

I’m sure there are many, but I’m just having trouble making the connection as to how I could engineer a solution that is better solved with dynamics as opposed to interfaces, dependency injection, etc.

So, what’s a real-world application scenario where dynamic type usage is appropriate?

  • 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-13T18:26:58+00:00Added an answer on May 13, 2026 at 6:26 pm

    There are lots of cases where you are already using dynamic typing and dynamic binding today. You just don’t realize it, because it is all hidden behind strings or System.Object, since until C# 4, the necessary support wasn’t there.

    One example is COM interop: COM is actually a semi-dynamic object system. When you do COM interop, a lot of methods actually return a dynamic object, but because C# didn’t support them, they were returned as System.Object and you had to cast them yourself, possibly catching exceptions on the way.

    Another example is interacting with dynamically typed (or even untyped) data, such as JSON, CSV, HTML, schemaless XML, schemaless web services, schemaless databases (which are, after all, the new hotness). Today, you use strings for those. An XML API would look like

    var doc = new XmlDocument("/path/to/file.xml");
    var baz = doc.GetElement("foo").GetElement("qux");
    

    and so on. But how about:

    dynamic doc = new XmlDocument("/path/to/file.xml");
    var baz = doc.foo.qux;
    

    Doesn’t that look nice?

    A third example is reflection. Today, invocation of a method via reflection is done by passing a string to InvokeMember (or whatever the thing is called). Wouldn’t it be nicer to, you know, just invoke the damn thing?

    Then, there is generation of dynamic data (basically the opposite of the second example). Here’s an example how to generate some dynamic XML:

    dynamic doc = new XmlBuilder();
    doc.articles(id=42, type="List", () => {
      article(() => {
        number(42);
        title("blahblubb");});});
    

    This is not nearly as beautiful as the equivalent Ruby, but it is the best I could come up with at such short notice 🙂

    And last but certainly not least, integration with a dynamically typed language. Whether that is JavaScript in a Silverlight application, a custom rules engine embedded in your business app or a DLR instance that you host in your CAD program/IDE/text editor.

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

Sidebar

Related Questions

I think I'm having a brain freeze here but I cannot figure out the
I think I have a basic understanding of this, but am hoping that someone
I have an issue that (I think) might have to do with scope, but
I think I have a basic understanding of REST, but something I'm stuck on
I have a quick question, because my brain refuses to think this evening. HTML
I think my brain died, but I thought there was a simple way of
Sometimes I think I haven't got the brain power for programming, I just can't
I think it is basically an easy problem, but I'm stuck. My brain is
I'm trying to wrap my brain around JMS and have been reading up on
Hopefully this is a silly question but my brain is fried and I can't

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.