Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to use &&(and) operator in the "if condition" in my code of ASP.NET.
My both operands on which i am applying && operator are int and int? respectively.
But it is showing error that, you can not apply && operator on int . How i can solve that error because i want to use && operator. Please help me.

What I have tried:

if(temp<=6){
if (check==1 && h=Convert.ToInt32(TextBox1.Text))
{
Label1.Text = "Sorry That group has corss its limits";

}
Posted
Updated 16-Mar-17 7:48am

You are not applying the operands on an int, you apply them only on bools.

If you look close at your second operand you can see the issue clearly. You are assigning the value of Convert.ToInt32 to whatever h is.
 
Share this answer
 
Comments
Richard Deeming 16-Mar-17 13:49pm    
Snap! :)
Hassaan_Malik 16-Mar-17 13:50pm    
Sorry i didn't get you point. By the way h is "int?"(null-able int). Would you like to slightly explain that?
That's a slightly misleading error message. The real problem is that you're missing an = in your second condition:
C#
h == Convert.ToInt32(TextBox1.Text)

With only a single =, you're setting the value of h to the value from TextBox1, rather than comparing it.

NB: You should probably use Int32.TryParse[^] instead of Convert.ToInt32, to avoid getting an exception if the user enters something that can't be converted to an integer.
 
Share this answer
 
Comments
Hassaan_Malik 16-Mar-17 13:56pm    
oh great. Its working ..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900