-
If Statement
I have a textBox1 in my C# project. How can i use the IF statement if the value of textBox1 is greater than or equal to 75, the remarks is "Passed" else "Failed".
I used:
int a;
string remarks;
a = int.Parse(textBox1.Text);
If (a>=75) then
remarks="Passed"
Else
remarks="Failed"
End If
Kindly correct this?
-
Code:
a = Convert.ToInt16(textBox1.Text);
If (a>=75)
remarks="Passed" ;
Else
remarks="Failed";
End If
-
Kovan? Your mixing up your VB.Net with C#....lol. Here is the correct way:
Code:
a = int.Parse(textBox1.Text);
if (a>=75)
remarks="Passed" ;
else
remarks="Failed";
That works if your if statement only processes one line of code. To process more than one line of code in an if block, you need to use the { } braces:
Code:
a = int.Parse(textBox1.Text);
if (a>=75)
{
remarks="Passed" ;
// use the braces if you have more than one line
// being processed.
}
else
{
remarks="Failed";
}