```
int m = matrix.GetLength(0);
int n = matrix.GetLength(1);
int[,] result = new int[m,n];
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
result[i, j] = 1;
}
}
for (int i = 0; i < m; ++i)
{
for (int j = 0; j < n; ++j)
{
if (matrix[i,j]!=0&&result[i,j]!=0)
{
result[i, j] = matrix[i, j];
}
if (matrix[i,j]==0)
{
for (int a = 0; a < m; a++ )
{
result[a, j] = 0;
}
for (int b = 0; b < n;b++ )
{
result[i, b] = 0;
}
}
}
}
matrix = result;
```