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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:03:54+00:00 2026-06-12T08:03:54+00:00

How can I convert from a System::Collections::ArrayList (containing System::String^ for example) to an array

  • 0

How can I convert from a System::Collections::ArrayList (containing System::String^ for example) to an array of cli::array<String^>?

  • 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-12T08:03:55+00:00Added an answer on June 12, 2026 at 8:03 am

    If the ArrayList is in your code and you can change it, consider changing it to a List<String^>. You’ll get type safety, cleaner code when using the class, more available Linq methods, and the normal builtin method on that class will return an array<String^> without having to jump through any hoops.


    There’s a builtin method on ArrayList to do this for you. Call ToArray, and specify the type of the array to be returned.

    ArrayList^ list = ...;
    array<String^>^ ar = reinterpret_cast<array<String^>^>(list->ToArray(String::typeid));
    

    If you’re doing this with other collection types (that aren’t using generics), you’ll have to do something more manual. You could do it by hand:

    ArrayList^ list = ...;
    array<String^>^ ar = gcnew array<String^>(list.Count);
    for(int i = 0; i < list.Count; i++)
        ar[i] = dynamic_cast<String^>(list[i]);
    

    Or you could use Linq to convert the ArrayList to an IEnumerable<String^>, and then convert that to an array of strings.

    ArrayList^ list = ...;
    array<String^> ar = Enumerable::ToArray(Enumerable::OfType<String^>(list));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I convert System.IObservable<string> to System.IObservable<System.Collections.Generic.List<string>> ? public static IObservable<List<string>> GetUrlList(Uri url) {
How can I convert TO a Nullable from a String using reflection? I have
To convert a date from string to Unix time, I can use date --date
The following code gives me this error: Cannot convert from 'System.Collections.Generic.List' to 'System.Collections.Generic.List'. How
The following code produces the issue Cannot implicitly convert type 'System.Collections.Generic.IEnumberable<DataField<string>>' to 'DataFields'. An
If I do the following I can convert from a time_struct object to a
How can I convert from bytes to float in php? Like in Java int
I have a class Something that implements ISomething . How can I convert/cast from
How can I convert a database from MySQL to MS SQL Server 2005?
Can someone please explain why I'm getting this error Type mismatch: cannot convert from

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.