0
  1. Hi can someone help me deleting array in multidimensional this code keeps on Array out of Bound

    ```
    int[,] Arr = {
      { 10,20,30,40},
      { 10,20,30,40},
      { 10,20,30,40}, 
      { 10,20,30,40}
    };
    
    int index = 1;
    for(int x = 0; x <= 3; x++) { 
        for (int i = index; i < Arr.Length - 1; i++)
        {
    
            Arr[i, x] = Arr[i + 1, x];
    
    
        }
    }
    ```
    
3
  • 1
    Once an array is initialized it is fixed - so how are you planning on deleting from it? For which values of i and x are you getting the exception? Commented Mar 23, 2020 at 11:41
  • Arr[i, x] = Arr[i + 1, x]; i think the x is the problem . i want to delete a specific row Commented Mar 23, 2020 at 11:46
  • Use a list instead of an array : List<Listint>> Arr = new List<List<int>>() { new List<int>() { 10,20,30,40}, new List<int>() { 10,20,30,40}, new List<int>() { 10,20,30,40}, new List<int>() { 10,20,30,40} }; Commented Mar 23, 2020 at 11:56

1 Answer 1

2

The Length property returns the length of the first dimension. When you want to access the other dimensions, you have to use the GetLength() method. See this SO.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.