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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:40:59+00:00 2026-06-01T19:40:59+00:00

Can we initialize an array of double[][][] as double[1][2][3] (this is not the correct

  • 0

Can we initialize an array of double[][][] as double[1][2][3] (this is not the correct syntax) using linq.

using for loop one way is

double[][][] myarr = new double[1][][];
for(int i=0; i<1; i++)
{
    myarr[i] = new double[2][];
    for(int j=0; j<2; j++)
    {
         myarr[i][j] = new double[3];
    }
}

but i want a cleaner code. I tried Select but it only fills first level. How to go about it. Thanks

& btw this is not homework!!

  • 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-01T19:41:01+00:00Added an answer on June 1, 2026 at 7:41 pm
    double[][][] threeDimensionArray = 
      Enumerable.Range(0, 1)
                .Select(h1 => Enumerable.Range(0, 2)
                                        .Select(h2 => new double[3])
                                        .ToArray())
                .ToArray();
    

    But this requires multiple ToArray() calls which doing memory copy (see implementaiton below) so for big number of items it would not be efficient so such kind of “elegant” solution is not for free. BTW, I would prefer for loop solution.

    Enumerable.ToArray() implementation: (credits to ILSpy)

    // System.Linq.Enumerable
    public static TSource[] ToArray<TSource>(this IEnumerable<TSource> source)
    {
        if (source == null)
        {
            throw Error.ArgumentNull("source");
        }
    
         // sll: see implementation of Buffer.ToArray() below
        return new Buffer<TSource>(source).ToArray();
    }
    
    // System.Linq.Buffer<TElement>
    internal TElement[] ToArray()
    {
        if (this.count == 0)
        {
            return new TElement[0];
        }
        if (this.items.Length == this.count)
        {
            return this.items;
        }
        TElement[] array = new TElement[this.count];
        Array.Copy(this.items, 0, array, 0, this.count);
        return array;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In C you can easily initialize an array using the curly braces syntax, if
You can initialize an array like this: int [ ] arr = { 1,
I know that we can initialise an array in one of two ways: Loop
We can initialize a container deque by using standard input like this: deque<int> c((istream_iterator<int>(cin)),(istream_iterator<int>()));
Is there a way I can initialize the following runtime array to all true
How can I initialize a const / static array of structs as clearly as
Can I declare an int array, then initialize it with chars? I'm trying to
I want to initialize an double array with size 200, and its value is
How can I define an array of decimals without explicitly casting each one? //decimal[]
In C++, I can statically initialize an array, e.g.: int a[] = { 1,

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.