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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:52:25+00:00 2026-06-09T11:52:25+00:00

I would like to populate a given dimension of a multidimensional array from a

  • 0

I would like to populate a given dimension of a multidimensional array from a LINQ select.
A loop would be an obvious way but I’d like a “best practise” suggestion.

For instance what the best way to insert this:

this.Facts.Select(f =>f.FactIc).ToArray()

which would return an array of longs into the second dimension of this array:

long[,] vals = new long[1, factCount];
  • 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-09T11:52:26+00:00Added an answer on June 9, 2026 at 11:52 am

    What about an array of arrays? If you find that you quite often need to replace the contents of 1 entire row then maybe each row should be an array in itself. You could even define your own class that contains the row data and then define an array of that class.

    BTW, why do you have ToList() and ToArray()?

    Edit: Assuming that the result must be a 2D array I would just use the version of foreach below:

    Define ForEach like this (this is my favourite extension method):

        public static IEnumerable<TSource> ForEach<TSource>(this System.Collections.Generic.IEnumerable<TSource> source, Action<TSource> action)
        {
            ThrowIfNull(source, "source");
            ThrowIfNull(action, "action");
    
            foreach (TSource item in source)
            {
                action(item);
            }
            return source;
        }
    
        public static IEnumerable<TSource> ForEach<TSource>(this System.Collections.Generic.IEnumerable<TSource> source, Action<TSource, int> action)
        {
            ThrowIfNull(source, "source");
            ThrowIfNull(action, "action");
    
            int index = 0;
            foreach (TSource item in source)
            {
                action(item, index);
                index++;
            }
            return source;
        }
    

    Then just do

    this.Facts.Select(f =>f.FactIc).ForEach((f, i) => vals[1, i] = f);
    

    You can’t really get much more efficient than this. The data is not in a flat array to start with so in some way you need to iterate each item and copy the data. This avoids making intermediate copies of the array etc.

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

Sidebar

Related Questions

I would like to populate a DateTime structure from a string, but it is
I would like to populate an 2 dimensional array, from a vector. I think
I have two divs. I would like to move/populate the text from div id
My question is quite simple I would like to create an array and populate
I would like to populate a combobox with the following: Visible item / Item
I have a view that I would like to populate data when the next
I have a MySQL database which contains data i would like to populate into
I would like to pre-populate a UITextfield with the phone number of the current
I am working on a children's book app and would like to dynamically populate
I am working on a children's book app and would like to dynamically populate

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.