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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:51:27+00:00 2026-05-18T03:51:27+00:00

I defined this multi dimensional array in C#: int[,] values = new int[,] {

  • 0

I defined this multi dimensional array in C#:

int[,] values = new int[,] { { 1, 2, 3 }, { 4, 5, 6 } };

Now the values are not longer in this form but in a Dictionary:

values2.Add("KeyA", new List<float> {1,4});
values2.Add("KeyB", new List<float> {2,5});
values2.Add("KeyC", new List<float> {3,6});

Now I’m trying to parse this dictionary in the two dimensional array again, but somehow there are problems:

List<float> outList = new List<float>();
values2.TryGetValue(values2.Keys.ElementAt(0) as string, out outList);

int[,] values = new int[outList.Count, values2.Keys.Count];

for (int i = 0; i < values2.Keys.Count; i++)
{
   List<float> list = new List<float>();
   values2.TryGetValue(values2.Keys.ElementAt(i), out list);

   for (int j = 0; j < list.Count; j++)
   {
       values[i, j] = Convert.ToInt32(list.ElementAt(j));
   }
}

This throws an InnerException: System.IndexOutOfRangeException. But why? I’m not able to convert the values properly.

Edit: I can be assumed that all the values in the dictionary have the same list length. I do check this somewhere else.

  • 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-18T03:51:28+00:00Added an answer on May 18, 2026 at 3:51 am

    I think it’s as simple as getting either your lengths or your indexing the wrong way round. Here’s your array creation:

    int[,] values = new int[outList.Count, values.Keys.Count];
    

    And you’re then setting values[i, j] where i is less than metrics.Keys.Count and j is less than list.Count.

    You could either switch the lengths round or set values[j, i] instead. Given the original statement of the array, I suspect you want the latter approach.

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

Sidebar

Related Questions

I have a multi-dimensional array in javascript defined as :- myArray[0][0] = Some IMage;
I have what amounts to a multi-dimensional array. int[][][] MyValues; What I want is
int array[5][3]; (obviously) creates a multi-dimensional C array of 5 by 3. However, int
I see variables defined with this type but I don't know where it comes
Note: This is a general programming question, not specific to any language, but feel
I am trying to work with a multi-dimensional array in MSVS2010 console application, and
I've a SDO_GEOMETRY column containing quite large multi polygons , defined like this: INSERT
This is my first post, I'm new to this site, but I've been lurking
this is my javascript code which for defining multidimensional array var array = new
I found this function to parse a csv string into a multi-dim array in

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.