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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:06:33+00:00 2026-06-18T15:06:33+00:00

I read about Type dynamic in C# 2010. (the corresponding msdn entry) I am

  • 0

I read about Type dynamic in C# 2010. (the corresponding msdn entry)

I am confused about the practical difference between T and dynamic while developing generic functions. My current tests didn’t show new ways to use dynamica way, that isn’t possible with T. In addition it seems, that dynamic needs much more time in runtime to achieve the same tasks.

Some example code to make my point clear:

// Sample Object
public class SampleObj
{
    public string Test { get; set; }
}

My Test-Method (measuring speed as well):

static void Main(string[] args)
{
    var sampleObj1 = new SampleObj { Test = "Test1" };
    var sampleObj2 = new SampleObj { Test = "Test2" };

    Stopwatch c1 = Stopwatch.StartNew();
    bool res1 = CompareObjectsT<SampleObj>(sampleObj1, sampleObj2);
    c1.Stop();
    Console.WriteLine("Comparison T: {0} time: {1} ms", res1, c1.ElapsedMilliseconds);


    Stopwatch c2 = Stopwatch.StartNew();
    bool res2 = CompareObjectsDyna(sampleObj1, sampleObj2);
    Console.WriteLine("Comparison dynamic: {0} time: {1} ms", res2, c2.ElapsedMilliseconds);
    c2.Stop();

    var instance = new X<SampleObj>();

    Console.ReadLine();
}

The result is:

Comparison T: False time: 6 ms
Comparison dynamic: False time: 3969 ms

The dynamic functions needs much more time, compared to the T comparison.

Decompiling my test application reveals heavy usage of reflection which may lead to this huge amount of time:

private static bool CompareObjectsDyna([Dynamic] object source1, [Dynamic] object source2)
{
    if (<CompareObjectsDyna>o__SiteContainer2.<>p__Site3 == null)
    {
        <CompareObjectsDyna>o__SiteContainer2.<>p__Site3 = CallSite<Func<CallSite, object, bool>>.Create(Binder.Convert(CSharpBinderFlags.None, typeof(bool), typeof(Program)));
    }
    if (<CompareObjectsDyna>o__SiteContainer2.<>p__Site4 == null)
    {
        <CompareObjectsDyna>o__SiteContainer2.<>p__Site4 = CallSite<Func<CallSite, Type, object, object, object>>.Create(Binder.InvokeMember(CSharpBinderFlags.None, "Equals", null, typeof(Program), new CSharpArgumentInfo[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.IsStaticType | CSharpArgumentInfoFlags.UseCompileTimeType, null), CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null), CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) }));
    }
    return <CompareObjectsDyna>o__SiteContainer2.<>p__Site3.Target(<CompareObjectsDyna>o__SiteContainer2.<>p__Site3, <CompareObjectsDyna>o__SiteContainer2.<>p__Site4.Target(<CompareObjectsDyna>o__SiteContainer2.<>p__Site4, typeof(object), source1, source2));
}

I considered this post but this hasn’t ansered my question.

Can someone tell me, in what scenario dynamic is much more effective than T?
(hopefully with a small practical sample)

  • 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-18T15:06:35+00:00Added an answer on June 18, 2026 at 3:06 pm

    Short answer is that generic type T must be known at compile time, but dynamic is inferred at runtime.

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

Sidebar

Related Questions

I just read about the reference device' device type in direct3D. http://msdn.microsoft.com/en-us/library/windows/desktop/bb219625(v=vs.85).aspx Does this
I read about using <context:component-scan base-package=tld.mydomain.business> <context:include-filter type=annotation expression=org.springframework.stereotype.Service/> </context:component-scan> and annotate my service
I read about IS OF TYPE and I expected that it should return TRUE,
Why this doesn't accept a parameter of a class-type? What can I read about
I have read several posts on SO about writing and compiling dynamic C# code.
I just considered using the new TDictionary type. But On QualityCentral I read about
I've read about CFRunLoop but still a bit confused about it. I came a
Read about Server push here . I want to push data to client from
Read about the issue in this stackoverflow question . Still have the same issue
Ive read about it and to be honest it all seems like a bunch

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.