We help IT Professionals succeed at work.

C# - The next empty [Row,Col] in myArray[320,4]

ocaccy asked
Having this int myArray[320,4].

Some parts have already been filled, but not filled until the [320,4].
How to know what [Row, Col] that is empty?

Watch Question

Awarded 2010
Top Expert 2013
If there is some integer that is guaranteed to never be in the array, then you could initialize the array to that value.

Since I think you are allowing for any value, you'll need to keep track somehow.
If you fill from left to right, then just keep a count.
If you fill randomly, then make an array of bools
bool myFlags[320, 4] = {false};
Then each time to fill a spot, change the false to true in the bool array.
Because you are using an int array, the default is zero and as previously pointed out, if zero is valid then you need to do something else.  If the array was object references instead then it would be very easy to tell because they would be null.

In the case like you described, I would init each element  to int.MinValue to indicate that it has not yet been used, assuming that int.MinValue is not valid for what you are doing.

Another option is to make it a int[320,8) and use the the col 4,5,6,7 as flags to indicate when the columns 0,1,2,3 have been used up.
int[320,8) should be int[320,8]
Or make it int[320,4,1) and use the 3 bound as a flag for each column.
Amro OsamaDevelopment, GIS Consultant - Haram Presidency
or just make it nullable
int?[,] x = new int?[320,4];

then if you want to check if its has been assigned or not:
{// it has a value

{// it does not have a value


and to get a value:
int value = x[10,1].Value;


I don`t want to leave this school.


Explore More ContentExplore courses, solutions, and other research materials related to this topic.