I'm fairly new to C# and I'm trying to understand certain things by testing different kinds of things. I just learned about get and set accessors and I want to try and utilize them as much as possible to avoid having to write a lot of get and set functions (which might not be unavoidable I guess). I want to run an if-statement in one of my getters and in that if-statement I want to do different things depending on the row and column in a multi-dimensional array, is there a way to know what row and coloumn I am trying to access?
Here's an example of the code I currently have and functionality I would like to have:
//What I have
private int[,] _array;
public int[,] Array {get => _array; set => _array = value; }
//Functionality I want to have
if(x_row < 0 || y_column < 0)
{
return something;
}
else
{
return something_else;
}
So depending on the row and column I would want to return different values. Is there a way to do that using accessors or am I better of just writing a get function?
Thanks!
Aucun commentaire:
Enregistrer un commentaire