I want to use switch like if in my code but I dont know how to use && in case ! this is my code
string a;
a = System.Convert.ToString(textBox1.Text);
if (a.Contains('h') && a.Contains('s'))
{
this.BackColor=Color.Red;
}
else if (a.Contains('r') && a.Contains('z'))
{
this.BackColor=Color.Black;
}
else if (a.Contains('a') && a.Contains('b'))
{
this.BackColor = Color.Pink;
}
textBox1.Text
is already a string. Don't bother callingConvert.ToString()
on it. There's no need.when
. I thought pattern matching was purely the whole type check they added toswitch
. Didn't even know you could add when expressions after all these months!