tags:

views:

140

answers:

1

I have a 2-dimensional array i need to convert first diagonal numbers in to zero,,for eg i need to convert first diagonal numbers of arrays[1 2 3 ] 5 9 5 3 2 1

means 1 9 1 in to zero that is the answer is just like [0 2 3] 5 0 5 3 2 0

Can you give me the required c# code in an Optimized way

+3  A: 

All you're doing is setting the points in the grid to be zero when X and Y are equal. (1,1), (2,2), and so on;

int x = 4, y = 5;
int[,] array = new int[x,y]; // assume we initialize this with some values
for (int i = 0; i < x && i < y; i++ ) {
    array[i,i] = 0;
}
Tony k
This will work but i need more optimized means by using LINQ or any other new things
peter
peter, this IS about as optimized as you can get. New technologies like LINQ will generally only make things easier, not faster.
Tony k