Save the coordinates of the given vertices of the rectangle
if ( s [ i ] [ j ] == ' * ' ) { if ( row . ContainsKey ( i ) ) { row [ i ] = row [ i ] + 1 ; } else { row . Add ( i , 1 ) ; } if ( col . ContainsKey ( j ) ) { col [ j ] = col [ j ] + 1 ; } else { col . Add ( j , 1 ) ; } } } } int x = 0 , y = 0 ; foreach ( KeyValuePair < int , int > entry in row ) { if ( entry . Value == 1 ) x = entry . Key ; } foreach ( KeyValuePair < int , int > entry in col ) { if ( entry . Value == 1 ) y = entry . Key ; }