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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:33:37+00:00 2026-05-16T10:33:37+00:00

There a section in my code where I need to invert a matrix. That

  • 0

There a section in my code where I need to invert a matrix. That can only reasonably be done on a square matrix, in this case a 3×3 square matrix. The tool I’m using to invert the matrix kept saying that my array wasn’t a proper square.

So I did a little test:

double[,] x = new double[3, 3];

MessageBox.Show(x.GetLength(0).ToString());
MessageBox.Show(x.GetLength(1).ToString());
MessageBox.Show(x.GetLength(2).ToString());

First one comes up as “3”. Second one comes up as “3”. Third one comes up as an IndexOutOfRangeException. Am I just overlooking something extremely obvious or… is this a little weird?

(Note: This is code from C# using .Net 2.0)

  • 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-16T10:33:38+00:00Added an answer on May 16, 2026 at 10:33 am

    You only have an array with two dimensions. Why would you expect asking for the size of the third dimensions to give you a valid result?

    The Array.GetLength() method return the number of elements in the specified dimension of the Array. In your case:

    x.GetLength(2).ToString();   // asking for size of third dimension
    

    you’re asking a 2-dimensional array what the size of it’s third dimension is. The result is an IndexOutOfRangeException. This is the expected behavior.

    In your code example, it looks like you may be confusing the size of each stated dimension, with the number of dimensions. Here are some examples of rectangular arrays of different dimensions:

    var d1 = new int[5];     // one dimensional array, containing 5 elements
    var d2 = new int[3,3];   // two-dimensional 3x3 element array
    var d3 = new int[2,2,2]; // three-dimension array of 2x2x2 elements
    var d4 = new int[2,5,6,8]; // four dimensional array, of 2x5x6x8 elements
    

    See the pattern? The number of dimensions is determined by how many numbers you specify in the array declaration. The sizes of each dimension is determined by the values of each number in the declaration.

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

Sidebar

Related Questions

I need this section of my code to run faster, as it is called
Is there a way to get InnoSetup constant value in [Code] section? I need
I've a section like this <mySection type=Namespace.MyClass, AssemblyName /> in my code I need
In some cases we need to be sure that some section of code won't
There is a requirement in Section 508 to code a Skip Navigation at the
There are some section in the table that does not contain any data and
There was some sample codes in the resource section, explaining some examples, that now
For some reason, I need to translate the virtual address of the code section
When editing javascript, if I need to comment out a large section of code
When typing code in a .aspx file (an MVC view in this case), Visual

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.