Am a newbie in C#. I have have created a list players with 2 radio button options for two teams.
Am able to add user input to the list but cant check if a name already exists in the list. Am using code below:
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace teamVal
{
public partial class Form1 : Form
{
List<String> teams;
public Form1()
{
InitializeComponent();
// Create lists
teams = new List<String> { };
}
private void btn_Submit2_Click(object sender, EventArgs e)
{
string newteamname = txt_TeamName.Text.Trim();
if (newteamname.Length == 0) return;
if (teams.Contains(newteamname))
{
lbl_TeamStatus.Text = newteamname + " already exists";
return;
}
if (rdo_Team1.Checked == true && (newteamname.Length > 0))
{
teams.Add(newteamname + ", Team 1");
lst_Teams.DataSource = null;
lst_Teams.DataSource = teams;
}
else if (rdo_Team2.Checked == true && (newteamname.Length > 0))
{
teams.Add(newteamname + ", Team 2");
lst_Teams.DataSource = null;
lst_Teams.DataSource = teams;
}
else
{
lbl_TeamStatus.Text = "You must check a team box";
return;
}
txt_TeamName.Text = String.Empty;
}
}
}