想让方法“checkuser”执行完之后返回布尔类型,以便在其它地方调用时可以用“if()”判断。但却发生了错误:错误 1 “tsleyyg.App_UL.UserInfo.checkuser(string, string)”: 并非所有的代码路径都返回值 C:\Users\Administrator\Desktop\tsleyyg09-12\tsleyyg\App_UL\UserInfo.cs 20 21 tsleyyg应该怎样改才能实现这种功能。代码:
public bool checkuser (string username, string password) 出错:1
{
username = username.Trim();
password = password.Trim();
string msgusername = "";
string msgpassword = "";
string msg = "";
if (username == "" || password == "")
{
if (username == "")
{
msgusername = "用户名不能为空!";
}
if (password == "")
{
msgpassword = "密码不能为空!";
} msg = msgusername + msgpassword; this.MsgBox(msg);
} } //弹出用户提示信息
public void MsgBox(string strMsg)
{
string StrScript;
StrScript = ("<script language=javascript>");
StrScript += ("alert('" + strMsg + "');");
StrScript += ("</script>");
System.Web.HttpContext.Current.Response.Write(StrScript);
}
public bool checkuser (string username, string password) 出错:1
{
username = username.Trim();
password = password.Trim();
string msgusername = "";
string msgpassword = "";
string msg = "";
if (username == "" || password == "")
{
if (username == "")
{
msgusername = "用户名不能为空!";
}
if (password == "")
{
msgpassword = "密码不能为空!";
} msg = msgusername + msgpassword; this.MsgBox(msg);
} } //弹出用户提示信息
public void MsgBox(string strMsg)
{
string StrScript;
StrScript = ("<script language=javascript>");
StrScript += ("alert('" + strMsg + "');");
StrScript += ("</script>");
System.Web.HttpContext.Current.Response.Write(StrScript);
}
解决方案 »
- 为什么我的..ToCharArray()不能用?菜鸟不懂啊 帮帮忙看下
- 利用飞信虚拟机脱离.net框架 出现错误
- 大家推荐一个好的国外开源的项目
- 急!请问数据集在.net2003中用得好好的,为什么2005不能用了?
- 用C#设计网页问题!
- Winform datagrid怎样让它不默认选中单元格
- 如何实现对于TreeView中的不同树节点有不同的右键菜单,如何实现(等ing online)
- 大家看看这个存储过程有什么问题了!
- pubs到底被什么程序在调用呢?
- 请问:ComponentOne Studio最新Q4零售企业版(带序列号)?
- 添加TreeView结点中图像文件到PictureBox
- 谁能帮我把DevComponents网站的一个帖子内容给读出来呢?
return true
if (username == "" || password == "")
{
if (username == "")
{
msgusername = "用户名不能为空!";
return false;
}
if (password == "")
{
msgpassword = "密码不能为空!";
return false;
} msg = msgusername + msgpassword; this.MsgBox(msg);
}
return true;
可你没有return,当然会报错
{
username = username.Trim();
password = password.Trim();
string msgusername = "";
string msgpassword = "";
string msg = "";
if (username == "" || password == "")
{
if (username == "")
{
msgusername = "用户名不能为空!";
return false;
}
if (password == "")
{
msgpassword = "密码不能为空!";
return false;
} msg = msgusername + msgpassword; this.MsgBox(msg);
return true;
} }
但是你的方法内却没有retrun语句所导致的
if (username == "")
{
msgusername = "用户名不能为空!";
}
else if (password == "")
{
msgpassword = "密码不能为空!";
}
else
{
b=true;
}return b;
{
string msg = "";
if (username.Trim().Equals(""))
{
msg = "用户名不能为空!";
}
if (password.Trim().Equals(""))
{
msg += "密码不能为空!";
}
if (!msg.Equals(""))
{
this.MsgBox(msg);
}
} //弹出用户提示信息
public void MsgBox(string strMsg)
{
string StrScript;
StrScript = ("<script language=javascript>");
StrScript += ("alert('" + strMsg + "');");
StrScript += ("</script>");
System.Web.HttpContext.Current.Response.Write(StrScript);
}
//不好意思 应该把 string 改成 void 因为是直接改的,没有编译
public string checkuser(string username, string password)