E
E
embiid2018-04-07 21:39:58
C++ / C#
embiid, 2018-04-07 21:39:58

How to change error: "Index is out of array bound"?

Please help fix the problem with the EnterMatrix method.
Exactly at:
MATRIX[j, k] = int.Parse(Console.ReadLine());

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Matrix {
    int row, column;
    int[,] MATRIX;

    public int ROW {
        get { return row; }
        set { row = value; }
    }

    public int COLUMN {
        get { return column; }
        set { column = value; }
    }

    public Matrix() {

    }

    public Matrix(int row, int column) {
        this.row = ROW;
        this.column = COLUMN;

        MATRIX = new int[this.COLUMN, this.ROW];
    }

    public void EnterMatrix() {
        Console.Write("Enter the numbers of matrix columns: ");
        COLUMN = int.Parse(Console.ReadLine());
        Console.Write("Enter the numbers of matrix rows: ");
        ROW = int.Parse(Console.ReadLine());

        for (int j = 0; j < COLUMN; j++) {
            for (int k = 0; k < ROW; k++) {
                Console.Write("For matrix cell -> " + (j + 1) + ":" + (k + 1) + " - ");
                MATRIX = new int[j, k];
                MATRIX[j, k] = int.Parse(Console.ReadLine());
            }
        }
    }

    public void DisplayMatrix() {
        Console.Write("The matrix is: ");
        for (int j = 0; j < COLUMN; j++) {
            for (int k = 0; k < ROW; k++) {
                Console.WriteLine("{0}\t", MATRIX[j, k]);
            }
        }
    }

    ~Matrix() {
        Console.WriteLine("Matrix has been denied.");
    }
}

class Vector : Matrix {
    public Vector(int row, int column) {
        
    }

    

    ~Vector() {
        Console.WriteLine("Vector has been denied.");
    }
}

class Program {
    static void Main() {
        Matrix MATRIX = new Matrix();
        MATRIX.EnterMatrix();
        MATRIX.DisplayMatrix();
    }
}

Answer the question

In order to leave comments, you need to log in

5 answer(s)
M
Maria Maltseva, 2018-04-07
@embiid

MATRIX = new int[j, k];
MATRIX[j, k] = int.Parse(Console.ReadLine());

In the loop, you allocate a new array [j, k] in memory each time - respectively, from 0 to (j - 1) and from 0 to (k - 1), and then access the cell [j, k].
It is necessary to take out the creation of an array for cycles
Console.Write("Enter the numbers of matrix columns: ");
COLUMN = int.Parse(Console.ReadLine());
Console.Write("Enter the numbers of matrix rows: ");
ROW = int.Parse(Console.ReadLine());
MATRIX = new int[COLUMN, ROW];

A
Alexander Yudakov, 2018-04-07
@AlexanderYudakov

https://docs.microsoft.com/en-us/dotnet/csharp/pro...
See 5th point

T
topbanana, 2014-02-24
@topbanana

change the addressing at home, the networks at home and in the office should be different.

F
FloMko, 2014-02-24
@FloMko

This is not so important, in most vpn clients it is possible to use the gateway of the vpn server, in the windows client, something like the properties of the vpn connection - network - a tick on "use the default gateway"

A
Archangel, 2014-02-28
@Archangel

The problem in any case is the intersection of networks. Either in the office or at home, you need to change the subnet. By the way, I highly recommend unchecking the "use the default gateway on the remote network" checkbox, otherwise a torrent launched at someone's home will set the office channel to zero, and given how you have a router, also the piece of iron itself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question