```
public bool SearchMatrix(int[,] matrix, int target) {
if (matrix == null) return false;
var len = matrix.GetUpperBound(0);
var row = 0;
var col = matrix.GetUpperBound(1);
while (row <= len && col >= 0)
{
if (matrix[row, col] > target) col--;
else if (matrix[row, col] < target) row++;
else return true;
}
return false;
}
```