meena moon

meena moon

  • NA
  • 39
  • 8.8k

How can reduce the number of Statements for this code in c#

Apr 18 2017 9:23 AM
Hi, how can I optimize my code? Reduce the number of lines(Statements) 
 
private void button1_Click(object sender, EventArgs e)
{
string[] seq1 = { "A", "C", "G", "T", "A", "C", "A", "G","T","G" };
string[] seq2 = { "T", "A", "C", "A", "C", "G","A","A","G","T" };
string[] res1 = new string[seq1.Length];
string[] res2 = new string[seq1.Length];
for (int i = 0; i <= 4; i++)
{
res1[i] = seq1[i];
res2[i] = seq2[i];
textBox1.Text +=" "+ res1[i];
textBox2.Text +=" "+ res2[i];
}
for(int i = 5; i < seq1.Length; i++)
{
if (seq1[i] == "T" )
{
res1[i] = "A";
}
else
if (seq1[i] == "A" )
{
res1[i] = "T";
}
else
if (seq1[i] == "C" )
{
res1[i] = "G";
}
else
if (seq1[i] == "G" )
{
res1[i] = "C";
}
textBox1.Text += res1[i]+" ";
}
for (int i = 5; i < seq2.Length; i++)
{
if (seq2[i] == "T")
{
res2[i] = "A";
}
else
if (seq2[i] == "A")
{
res2[i] = "T";
}
else
if (seq2[i] == "C")
{
res2[i] = "G";
}
else
if (seq2[i] == "G")
{
res2[i] = "C";
}
textBox2.Text += res2[i] + " ";
}
}
 

Answers (6)