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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:01:37+00:00 2026-06-03T03:01:37+00:00

I need to create a heterogeneous List of objects (custom classes). My first thought

  • 0

I need to create a heterogeneous List of objects (custom classes). My first thought was to create a List<ISomeMarkerInterface> but I quickly learned that this is not what I want. My next thought was List<dynamic> and this didn’t seem to be a bad idea. However, I was doing some research and came across this article about boxing and unboxing and in the example, they’re doing basically what I want using List<Object>.

Aside from the fact that dynamic will be evaluated at runtime and Object at compile-time, what is the difference between List<dynamic> and List<Object>? Aren’t they essentially the same thing?

  • 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-03T03:01:41+00:00Added an answer on June 3, 2026 at 3:01 am

    There are 3 “general” types (although not all are real types) in C#: object, var and dynamic.

    Object

    An actual type, like any other type, with one special rule: if a type doesn’t inherit, it inherits from object. From this, it follows that all types inherit from object, directly or indirectly.

    Emphasis: object is a type. An object can be of type object, and the type has its methods, like ToString(). Since everything inherits from object, everything can be upcast into object. When you assign an object to an object reference, you are doing upcasting just like when you assign an Elephant type object to an Animal reference where Elephant inherits from Animal.

    SomeType x = new SomeType();
    object obj = x;
    obj.DoSomething();
    
    • obj is treated as being of type object at compile time, and will be of type object at runtime (which is logical, since it is an actual type – obj is declared as object so can only be of that type)
    • obj.DoSomething() will cause a compile-time error, as object does not have this method, regardless of whether SomeType has it.

    Var

    This is not an actual type, it is merely shorthand for “compiler, figure out the type for me based on the right side of the assignment”.

    SomeType x = new SomeType();
    var obj = x;
    obj.DoSomething();
    
    • obj is treated as being of type SomeType at compile time, and will be of type SomeType at runtime, just as if you had written “SomeType” instead of “var”.
    • if SomeType has a method DoSomething(), this code will work
    • if SomeType doesn’t have the method, the code will cause a compile-time error

    Dynamic

    This is a type that tells the compiler to disable compile-time type checking on the variable. An object is treated as having the type dynamic at compile-time and run-time.

    SomeType x = new SomeType();
    dynamic obj = x;
    obj.DoSomething();
    
    • obj is of type dynamic at compile and run time
    • if SomeType has a method DoSomething(), this code will work
    • if SomeType doesn’t have the method, the code will compile, but throw an exception at run-time
    • note that dynamic can cause exceptions very easily if used carelessly:

      public void f(dynamic x)
      { 
          x.DoSomething();
      }
      

    This will throw an exception if x is of a type that doesn’t have the DoSomething method, but it will still be possible to call it and pass any object as the parameter without a compile-time error, causing an error that only shows itself at run-time, and possibly only in specific circumstances – a potential bug. So if you use dynamic in any kind of public interface of a class, you should always manually type-check at runtime using reflection, carefully deal with exceptions, or not do it in the first place.

    Note: the object being referred to never changes its type, of course. While obj may be object, the x that it refers to is still SomeType.

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

Sidebar

Related Questions

this is my first post here. I need create a feed like facebook with
I need create a css like this: .word-remain+textarea{clear: before} but I cannot write this
I need create a list of RadioButtons, but if I try to do it
I need create a stored proc that will return a list of a code,
I need create custom dialog and put JPanel into it. Is it possible?
i need create an email list sending to many emails. what is best solution
I need create clone repository. but I do not know where can I get
Need to create a custom DNS name server using C which will check against
I need create menu for widget like this https://www.gstatic.com/android/market/com.bugabuga.switcher/ss-320-0-0 . What components are used?
I have 2 tables(Companies and Contacts). I need create a list of all of

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.