Store the primary diagonal elements
List < int > priDiag = new List < int > ( ) ; while ( i < mat . GetLength ( 0 ) ) { priDiag . Add ( mat [ i , j ] ) ; i += 1 ; j += 1 ; } i = 0 ; j = mat . GetLength ( 0 ) - 1 ;