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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:27:35+00:00 2026-05-24T18:27:35+00:00

I have an ArrayList of objects that are of a certain type, and I

  • 0

I have an ArrayList of objects that are of a certain type, and I need to convert this ArrayList in to a types list. Here is my code

Type objType = Type.GetType(myTypeName);

ArrayList myArrayList = new ArrayList();

object myObj0 = Activator.CreateInstance(type);
object myObj1 = Activator.CreateInstance(type);
object myObj2 = Activator.CreateInstance(type);

myArrayList.Add(myObj0);
myArrayList.Add(myObj1);
myArrayList.Add(myObj2);

Array typedArray = myArrayList.ToArray(objType);  // this is typed
object returnValue = typedArray.ToList();  // this is fake, but this is what I am looking for

There is no ToList() available for an Array, this is the behaviour I am looking for

object returnValue = typedArray.ToList();

So basically I have the type name as a string, I can create a Type from the name, and create a collection containing several objects typed, but how do I convert that to a List? I am hydrating a property and when I do a SetValue my property type needs to match.

Thank you very much.

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

    If you’re using .NET 4, dynamic typing can help – it can perform type inference so you can call ToList, admittedly not as an extension method:

    dynamic typedArray = myArrayList.ToArray(objType);    
    object returnValue = Enumerable.ToList(typedArray);
    

    Otherwise, you’ll need to use reflection:

    object typedArray = myArrayList.ToArray(objType);   
    // It really helps that we don't need to work through overloads...
    MethodInfo openMethod = typeof(Enumerable).GetMethod("ToList");
    MethodInfo genericMethod = openMethod.MakeGenericMethod(objType);
    object result = genericMethod.Invoke(null, new object[] { typedArray });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ArrayList<String> that I'd like to return a copy of. ArrayList has
I have an arraylist that contains items called Room. Each Room has a roomtype
I need to make an ArrayList of ArrayLists thread safe. I also cannot have
In Java, say you have a class that wraps an ArrayList (or any collection)
Closed as exact duplicate of this question . I have an array/list of elements.
I've currently got a spreadsheet type program that keeps its data in an ArrayList
I have an array/list/collection/etc of objects. For sample purposes, lets assume it is just
I have a ArrayList made up of different elements imported from a db, made
I have an ArrayList<String> , and I want to remove repeated strings from it.
I have some data stored as ArrayList . And when I want to backup

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.