Reputation: 43
For some reason the If statements are always going through no matter what I put. Even if i did things like True == False or 0 == 1 it still goes through. What I am trying to do is detect if the text is null and set it to - so it doesn't error.
This is my code inside the button
private void SearchButton_Click(object sender, EventArgs e)
{
reg = String.IsNullOrWhiteSpace(RegText.Text);
if (reg == true);
{
RegText.ResetText();
RegText.AppendText("-");
}
model = String.IsNullOrWhiteSpace(ModelText.Text);
if (model == true) ;
{
ModelText.ResetText();
ModelText.AppendText("-");
}
for (int i = 0; i < MaxCars; i++)
{
if (regos[i].Equals(Convert.ToString(RegText.Text)) || models[i].Equals(Convert.ToString(ModelText.Text)) || price[i] == Convert.ToInt32(PriceText.Text))
{
Console.WriteLine(regos[i] + " " + models[i] + " " + price[i]);
}
}
}
Upvotes: 0
Views: 88
Reputation: 1408
You have put ; at the end of every if that is causing an error. This is the code with fix:
private void SearchButton_Click(object sender, EventArgs e)
{
reg = String.IsNullOrWhiteSpace(RegText.Text);
if (reg == true)
{
RegText.ResetText();
RegText.AppendText("-");
}
model = String.IsNullOrWhiteSpace(ModelText.Text);
if (model == true)
{
ModelText.ResetText();
ModelText.AppendText("-");
}
for (int i = 0; i < MaxCars; i++)
{
if (regos[i].Equals(Convert.ToString(RegText.Text)) || models[i].Equals(Convert.ToString(ModelText.Text)) || price[i] == Convert.ToInt32(PriceText.Text))
{
Console.WriteLine(regos[i] + " " + models[i] + " " + price[i]);
}
}
}
Upvotes: 1