The following code will open up a Message Box containing the word "Fail".
Is there a way to make the if statement case insensitive, so that the if statement passes and opens a mbox containg "Pass" without converting the character/string to upper/lower case?
here is the code:
public partial class Form1 : Form
{
string one = "A";
string two = "a";
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (one == two)
{
MessageBox.Show("Pass");
}
else
{
MessageBox.Show("Fail");
}
}
}
Thanks in advance
You could use this
string.Equals(one, two, StringComparison.CurrentCultureIgnoreCase)
Your code would be
if (string.Equals(one, two, StringComparison.CurrentCultureIgnoreCase))
{
MessageBox.Show("Pass");
}
else
{
MessageBox.Show("Fail");
}
Using CurrentCultureIgnoreCase :
Compare strings using culture-sensitive sort rules, the current culture, and ignoring the case of the strings being compared.
More info here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With