How do you check if a method returned true?

Public bool SqlCheck(string username, string password) 
{
    // sql checks here 
    return true
} 

How to check if it returned true or false in my main method? Sample code would be helpful.

Does boolean have a default value that I should be aware of?

+5
source share
7 answers

You just have something like:

bool result = SqlCheck(username, password);

if (result)
{
    // Worked!
}
else
{
    // Failed
}

If you do not need the result after the test, you can simply:

if (SqlCheck(username, password))
{
    // Worked!
}
else
{
    // Failed
}

boolby default false.

+13
source

The easiest way is:

if (SqlCheck(username, password))
{
    // SqlCheck returned true
}
else
{
    // SqlCheck returned false
}
+3
source

IF (true false),

MSDN if .

 if (SqlCheck("UserName", "Password"))
 {
     // SqlCheck returns true
 }
 else 
 {
     // SqlCheck returns false
 } 


public bool SqlCheck(string username, string password) 
{
 // sql checks here 
    return true;
} 

, .

 bool sqlCheckResult= SqlCheck("UserName", "Password");
 if (sqlCheckResult)
 {
     // SqlCheck returns true
 }
 else 
 {
     // SqlCheck returns false
 } 

 // do something with your sqlCheckResult variable

+3

#, , main, SqlCheck, ?

-:

public void function main()
{
    bool result = SqlCheck('martin', 'changeme');

    if (result == true) {
        // result was true
    } else {
        // result was false
    }
}
+3

Boolean - , if s, while s, for ...NET. :

if (SqlCheck(string username, string password) ) {
    // This will be executed only if the method returned true
}

bool false. /: .

+1

:

bool sqlCheck = SqlCheck("username", "password");

if(sqlCheck) // ie it is true
{
    // do something
}

true , , , sql .

0
bool myCheck = SqlCheck(myUser, myPassword);

bool myCheck = SqlCheck("user", "root");

....

if (myCheck) {
    // succeeded
} else {
    //failed
}
0

All Articles