I
I
i__egor2019-01-16 18:12:16
C++ / C#
i__egor, 2019-01-16 18:12:16

How to write a c get and set property for a two dimensional array?

How to write a c get and set property for a two-dimensional array to check if it is out of bounds, if it is out, then do not set the value or get 0 in get ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
LiptonOlolo, 2019-01-16
@LiptonOlolo

Limits are constants, then:

const int Size1 = 10;
const int Size2 = 20;

int[,] matrix;
public int[,] Matrix
{
  get => matrix;
  set
  {
    if (value.GetLength(0) > Size1 || value.GetLength(1) > Size2)
    {
      Console.WriteLine("Матрица вышла за пределы 10х20");
    }
    else matrix = value;
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question