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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:14:38+00:00 2026-06-03T06:14:38+00:00

Here is my code: MyClass here = new MyClass(); IEnumerable<MyClass> vats = (IEnumerable<MyClass>)here.All(); The

  • 0

Here is my code:

MyClass here = new MyClass();
IEnumerable<MyClass> vats = (IEnumerable<MyClass>)here.All();

The All() method returns IEnumerable<dynamic>. I want to convert it to IEnumerable<MyClass>. The line above doesn;t work, it says Unable to cast object of type ‘d__15’ to type ‘System.Collections.Generic.IEnumerable`1[MyClass]’.

I also tried:

 IEnumerable<MyClass> vats = here.All() as IEnumerable<MyClass>;

but it returns null.

  • 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-03T06:14:40+00:00Added an answer on June 3, 2026 at 6:14 am

    Similar to dbaseman’s answer (and AKX’s comment) I’d use Cast:

    IEnumerable<MyClass> vats = here.All().Cast<MyClass>();
    

    You’ll need a using directive for LINQ though:

    using System.Linq;
    

    at the top of your file. It sounds like you haven’t got that if the Select method isn’t recognized.

    Note that this assumes that each value really is a MyClass reference.

    EDIT: If you want to be able to access the values by index, I’d recommend using ToList:

    List<MyClass> vats = here.All().Cast<MyClass>().ToList();
    

    While ToArray would work too, I personally favour lists over arrays in most cases, as they’re rather more flexible.

    EDIT: It sounds like your results are actually full of ExpandoObject. You’ll need to create a new instance of MyClass from each item, e.g.

    List<MyClass> vats = here.All()
                             .Select(item => new MyClass(item.Name, item.Value))
                             .ToList();
    

    or possibly:

    List<MyClass> vats = here.All()
                             .Select(item => new MyClass {
                                         Name = item.Name,
                                         Value = item.Value,
                                     })
                             .ToList();
    

    That’s just an example, which I wouldn’t expect to work straight away – we can’t do any better than that as we know nothing about how your results are actually being returned.

    It does sound like you’re in over your head here, I’m afraid.

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

Sidebar

Related Questions

How to convert this code: MYCLASS ebt = new MYCLASS(); ebt.cbStruct = Marshal.SizeOf(ebt); into
I have some code here private void Run() { MyClass c = new MyClass();
Here's a piece of code: $obj = new myClass(); $obj->{$_GET[func]}($_GET[param]) It works based on
So here is my code: public MyClass (int y) { super(y,x,x); //some code }
enter code here Hi All, I have a simple windows service application that connects
Here's some code: class myclass { enum STAT { IDLE=0; READING, WRITING, PAINTING, SKATTING
Here is the code: public class MyClass implements Inreface1, Inreface2 { public MyClass() {
The below is my code, public class Myclass{ some code is here. } public
Hi all first post here :) Let's start with a snippet of the code
I use the following code to execute a method with delayed job: class MyClass

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.