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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:42:34+00:00 2026-05-31T15:42:34+00:00

I need to convert the following collection into double[,]: var ret = new List<double[]>();

  • 0

I need to convert the following collection into double[,]:

 var ret = new List<double[]>();

All the arrays in the list have the same length. The simplest approach, ret.ToArray(), produces double[][], which is not what I want. Of course, I can create a new array manually, and copy numbers over in a loop, but is there a more elegant way?

Edit: my library is invoked from a different language, Mathematica, which has not been developed in .Net. I don’t think that language can utilize jagged arrays. I do have to return a multidimensional array.

  • 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-31T15:42:35+00:00Added an answer on May 31, 2026 at 3:42 pm

    I don’t believe there’s anything built into the framework to do this – even Array.Copy fails in this case. However, it’s easy to write the code to do it by looping:

    using System;
    using System.Collections.Generic;
    
    class Test
    {
        static void Main()
        {
            List<int[]> list = new List<int[]>
            {
                new[] { 1, 2, 3 },
                new[] { 4, 5, 6 },
            };
    
            int[,] array = CreateRectangularArray(list);
            foreach (int x in array)
            {
                Console.WriteLine(x); // 1, 2, 3, 4, 5, 6
            }
            Console.WriteLine(array[1, 2]); // 6
        }
    
        static T[,] CreateRectangularArray<T>(IList<T[]> arrays)
        {
            // TODO: Validation and special-casing for arrays.Count == 0
            int minorLength = arrays[0].Length;
            T[,] ret = new T[arrays.Count, minorLength];
            for (int i = 0; i < arrays.Count; i++)
            {
                var array = arrays[i];
                if (array.Length != minorLength)
                {
                    throw new ArgumentException
                        ("All arrays must be the same length");
                }
                for (int j = 0; j < minorLength; j++)
                {
                    ret[i, j] = array[j];
                }
            }
            return ret;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to convert all of the following forms into .NET Uri object: hello.world
Hey everyone, I need to convert the following format into a new format using
I have the following int 7122960 I need to convert it to 71229.60 Any
I need to convert a Joda-Time DateTime into a String, in the following format:
I have the following FORTRAN code which I need to convert to C or
I need to convert all values in a structure (arguments passed into a function)
I need to convert this following XAML into code-behind: <ComboBox SelectedItem={Binding Level} ItemsSource={Binding Levels}
I need to convert the following java method to scala and am having difficulty
I need to convert a time difference (diff) between two actions into a human
I need to convert a column data into single row with multiple columns Example

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.