return global variable value set inside loop
public class loginbal
{
public static bool match = false ;
public bool check(string username, string password)
{
logindal LGD = new logindal();
DataSet ds1= LGD.logincheck(username, password);
int noofrows = ds1.Tables["login"].Rows.Count;
for (int i = 0; i < noofrows; i++)
{
if ((ds1.Tables["login"].Rows[i]["username_l"].ToString() == username) && (ds1.Tables["login"].Rows[i]["password_l"].ToString() == password))
{
ma开发者_JS百科tch = true;
}
}
return match;
}
I want to return match
but its not affected with for loop set statement what i can do to change match according to for loop value and return to method?
As @BrokenGlass and @NullUserException have pointed out, there is no need for a variable match
, much less a static one. Just return true
if the loop finds a match. If it doesn't, return false
.
public bool check(string username, string password)
{
logindal LGD = new logindal();
DataSet ds1= LGD.logincheck(username, password);
int noofrows = ds1.Tables["login"].Rows.Count;
for (int i = 0; i < noofrows; i++)
{
if ((ds1.Tables["login"].Rows[i]["username_l"].ToString() == username)
&& (ds1.Tables["login"].Rows[i]["password_l"].ToString() == password))
{
return true;
}
}
return false;
}
精彩评论