private void NumberOfUnitsHostNameButton_Click(object sender, RoutedEventArgs e) { bool flag = false; List <Host> mylist = bl.GetHostsList(); foreach (var item in mylist) { if (NumberOfUnitsHostNameTextBox.Text == item.HostId) { flag = true; } } if (flag) { int temp = bl.getNumOfUnits(NumberOfUnitsHostNameTextBox.Text); answerNumberOfUnitsTextBlock.Text = "The number of units this host has is: " + temp; } else { string titel = "Oops"; string err = "Cannot find a Host with this ID."; MessageBox.Show(err, titel); } }