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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:35:01+00:00 2026-05-23T08:35:01+00:00

This would be pretty straight forward if I knew the types at compile time

  • 0

This would be pretty straight forward if I knew the types at compile time or if it was a generic parameter, because I could do something like myArray.Cast<T>() But what I actually have is essentially this. I do not have a known type or generic parameter. I have a System.Type variable.

// could actually be anything else
Type myType = typeof(string);  

// i already know all the elements are the correct types
object[] myArray = new object[] { "foo", "bar" }; 

Is there some kind of reflection magic I can do to get a string[] reference containing the same data? (where string isn’t known at compile time)

  • 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-23T08:35:02+00:00Added an answer on May 23, 2026 at 8:35 am

    It’s not really a cast as such (I’m allocating a new array and copying the original), but maybe this can help you out?

    Type myType = typeof(string);
    object[] myArray = new object[] { "foo", "bar" };
    
    Array destinationArray = Array.CreateInstance(myType, myArray.Length);
    Array.Copy(myArray, destinationArray, myArray.Length);
    

    In this code, destinationArray will be an instance of string[] (or an array of whatever type myType was).

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

Sidebar

Related Questions

If the array was null-terminated this would be pretty straight forward: unsigned char u_array[4]
This question is pretty straight forward, I literally just want to stream video of
This is a pretty straight forward attempt. I haven't been using python for too
It's a pretty straight forward question. I'd like to be able to provide feedback
Okay at first I thought this would be pretty straightforward. But I can't think
This should be pretty straightforward I would think. I have this string: [quote=Joe Johnson|1]Hi![/quote]
I thought this would be pretty easy but I'm running into all sorts of
So! My question is pretty straight forward, I have a website (Build in ASP.NET
I'm having a problem updating a table and im sure its pretty straight forward
The question is pretty straight forward. For clarity, consider the example below: // Note

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.