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 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 what amounts to a multi-dimensional array. int[][][] MyValues; What I want is
I have seen this macro defined before but never really knew its purpose. Can
I have a ComponentResourceKey defined in my resource dictionary like this: <Style x:Key={ComponentResourceKey TypeInTargetAssembly={x:Type
I read the example on Passing multi-dimensional arrays in C on this site. It
Okay, I have a multi-dimensional array which is statically-allocated. I'd very much like to
I am trying to share a multi-dimensional hash over multiple threads. This hash holds
After creating a multi-dim array like this, how do I sort it? Assuming 'markers'
Is this defined by the language? Is there a defined maximum? Is it different
I have this code: CCalcArchive::CCalcArchive() : m_calcMap() { } m_calcMap is defined as this:
I have a GridView defined like this: <asp:GridView ID=myGridView ruant=server> <asp:BoundField DataField=myField /> <asp:CommandField

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.