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?
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.
bool
false
The easiest way is:
if (SqlCheck(username, password)) { // SqlCheck returned true } else { // SqlCheck returned false }
IF (true false),
IF
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
#, , main, SqlCheck, ?
main
SqlCheck
-:
public void function main() { bool result = SqlCheck('martin', 'changeme'); if (result == true) { // result was true } else { // result was false } }
Boolean - , if s, while s, for ...NET. :
if
while
for
if (SqlCheck(string username, string password) ) { // This will be executed only if the method returned true }
bool false. /: .
:
bool sqlCheck = SqlCheck("username", "password"); if(sqlCheck) // ie it is true { // do something }
true , , , sql .
bool myCheck = SqlCheck(myUser, myPassword);
bool myCheck = SqlCheck("user", "root");
....
if (myCheck) { // succeeded } else { //failed }