As seen from the code given in the question
double cols = double.Parse(textBox2.Text);
double len = text.Length;
cols
is used for the matrix size, so it is preferable to have it as
int
.
The property
text.Length
is of type
int
and it can be used as it is and there is no need to assign to a local variable.
double test = len / cols;
if (test % 1 == 0)
can be given as an
else if
like
else if (len % cols != 0)
label3.Text = "The text length shall be equal to rows * cols ";
The transposition can be done in the
else
block
By taking
row, cols
as int the cast
(int)
can be avoided.
Further for transpose
1. The matrix can be declared with
text.Length /cols
as rows and
cols
as columns.
2. Each element in the matrix can be assigned by using for loop on text like
matrix[i/cols,i%cols]=text[i];