I have three buttons each with the same loop but different string can I shorten it to one loop so I don't have to keep reusing the loop?
public static string VarOutput { get; set; }
async private void btnCourse1_Click(object sender, RoutedEventArgs e)
{
string VarOutput = "";
string[] names = new string[3] { "COP3488C,", "UWP1,", "This course is mobile app development." };
for (int i = 0; i < names.Length; i++)
{
VarOutput = VarOutput + names[i] + " ";
}
txtBoxCourse.Text = VarOutput;
var dialog = new MessageDialog(VarOutput);
await dialog.ShowAsync();
}
async private void btnCourse2_Click(object sender, RoutedEventArgs e)
{
string VarOutput = "";
string[] names = new string[3] { "DOP3488B,", "UWC1,", "This course is Cloud Computing." };
for (int i = 0; i < names.Length; i++)
{
VarOutput = VarOutput + names[i] + " ";
}
txtBoxCourse.Text = VarOutput;
var dialog = new MessageDialog(VarOutput);
await dialog.ShowAsync();
}
async private void btnCourse3_Click(object sender, RoutedEventArgs e)
{
string VarOutput = "";
string[] names = new string[3] { "BOP3589,", "UWP2,", "This course Computer Programming Java 1." };
for (int i = 0; i < names.Length; i++)
{
VarOutput = VarOutput + names[i] + " ";
}
txtBoxCourse.Text = VarOutput;
var dialog = new MessageDialog(VarOutput);
await dialog.ShowAsync();
}
can I shorten it to one loopyesstring VarOutput = string.Join(" ", names);