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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:12:32+00:00 2026-05-14T04:12:32+00:00

I get an IEnumerable which I know is a object array. I also know

  • 0

I get an IEnumerable which I know is a object array. I also know the datatype of the elements. Now I need to cast this to an IEnumerable<T>, where T is a supplied type. For instance

IEnumerable results = GetUsers();
Type t = GetType(); //Say this returns User
IEnumerable<T> users = ConvertToTypedIEnumerable(results, t);

I now want to cast/ convert this to IEnumerable<User>. Also, I want to be able to do this for any type.

I cannot use IEnumerable.Cast<>, because for that I have to know the type to cast it to at compile time, which I don’t have. I get the type and the IEnumerable at runtime.

–
Thanks

  • 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-14T04:12:33+00:00Added an answer on May 14, 2026 at 4:12 am

    You can use reflection to call Cast<> with a runtime type. See this answer: How to call a generic method through reflection

    However, at some point you’ll still have to know the type of the item at compile time if you ever want to manipulate it as such without reflection. Just having an IEnumerable<T> instance cast as an object/IEnumerable still won’t really do you any more good than just having the IEnumerable by itself. It’s likely that you need to rethink what you’re doing.

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

Sidebar

Ask A Question

Stats

  • Questions 501k
  • Answers 501k
  • 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 Two options - using LIMIT: SELECT yt.numeric_column FROM YOUR_TABLE yt… May 16, 2026 at 2:08 pm
  • Editorial Team
    Editorial Team added an answer You need to post the form data back to the… May 16, 2026 at 2:08 pm
  • Editorial Team
    Editorial Team added an answer Yes, it absolutely maters when [super dealloc] is called. Once… May 16, 2026 at 2:08 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I got this síngleton cache object and it exposes an IEnumerable property which just
I'm trying to upcast a parameter passed as an object (which is an upcast
See i have a situation like this... object myRoledata = List<Roles>() --> (some list
I cannot figure this out. The workflow of passing IEnumerable<T> (T is some my
I'm using a custom message that inherits the System.Servicemodel.Channels.Message. My custom message get IEnumerable
I know it must have been asked more than twice, but I could not
This little bit of code will help me describe my problem: public class Car
I have a list of object I wish to sort in C#.Net 3.5, the
i really dont get it work. say i have some classes with the same
I have specified a couple of interfaces, which I am implementing as entities using

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.