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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:00:56+00:00 2026-05-11T18:00:56+00:00

I’m very excited about the dynamic features in C# ( C#4 dynamic keyword –

  • 0

I’m very excited about the dynamic features in C# (C#4 dynamic keyword – why not?), especially because in certain Library parts of my code I use a lot of reflection.

My question is twofold:

1. does "dynamic" replace Generics, as in the case below?

Generics method:

public static void Do_Something_If_Object_Not_Null<SomeType>(SomeType ObjToTest) {
        
        //test object is not null, regardless of its Type
        if (!EqualityComparer<SomeType>.Default.Equals(ObjToTest, default(SomeType))) {
            //do something
        }
    }

dynamic method(??):

public static void Do_Something_If_Object_Not_Null(dynamic ObjToTest) {

        //test object is not null, regardless of its Type?? but how?
        if (ObjToTest != null) {
            //do something
        }
    }

2. does "dynamic" now allow for methods to return Anonymous types, as in the case below?:

 public static List<dynamic> ReturnAnonymousType() {
        return MyDataContext.SomeEntities.Entity.Select(e => e.Property1, e.Property2).ToList();
    }

cool, cheers

EDIT:

Having thought through my question a little more, and in light of the answers, I see I completely messed up the main generic/dynamic question. They are indeed completely different. So yeah, thanks for all the info.

What about point 2 though?

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

    dynamic might simplify a limited number of reflection scenarios (where you know the member-name up front, but there is no interface) – in particular, it might help with generic operators (although other answers exist) – but other than the generic operators trick, there is little crossover with generics.

    Generics allow you to know (at compile time) about the type you are working with – conversely, dynamic doesn’t care about the type.
    In particular – generics allow you to specify and prove a number of conditions about a type – i.e. it might implement some interface, or have a public parameterless constructor. dynamic doesn’t help with either: it doesn’t support interfaces, and worse than simply not caring about interfaces, it means that we can’t even see explicit interface implementations with dynamic.

    Additionally, dynamic is really a special case of object, so boxing comes into play, but with a vengence.

    In reality, you should limit your use of dynamic to a few cases:

    • COM interop
    • DLR interop
    • maybe some light duck typing
    • maybe some generic operators

    For all other cases, generics and regular C# are the way to go.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The quickest and safest thing to do would be to… May 12, 2026 at 12:40 am
  • Editorial Team
    Editorial Team added an answer Well stored procedures are not composable. So there is no… May 12, 2026 at 12:40 am
  • Editorial Team
    Editorial Team added an answer A quick look indicates that this in your CSS may… May 12, 2026 at 12:40 am

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
Configuring TinyMCE to allow for tags, based on a customer requirement. My config 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.