想让方法“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);
          }

解决方案 »

  1.   

    1.函数最后没返回值。加一句
    return true
      

  2.   


     if (username == "" || password == "")
      {
      if (username == "")
      {
      msgusername = "用户名不能为空!";
       return false;
      }
      if (password == "")
      {
      msgpassword = "密码不能为空!";
    return false;
      }  msg = msgusername + msgpassword;  this.MsgBox(msg);
    }
    return true;
      

  3.   

    你的函数定义的是有返回值的
    可你没有return,当然会报错
      

  4.   

    错误 1“tsleyyg.App_UL.UserInfo.checkuser(string, string)”: 并非所有的代码路径都返回值    给的提示已经很明确了  你写的函数没有返回值啊  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 = "用户名不能为空!";
      return false;
      }
      if (password == "")
      {
      msgpassword = "密码不能为空!";
      return false;
      }  msg = msgusername + msgpassword;  this.MsgBox(msg);
       return true; 
        
        
      }  }
      

  5.   

      public bool checkuser (string username, string password)你的方法返回类型是bool
    但是你的方法内却没有retrun语句所导致的
      if (username == "")
      {
      msgusername = "用户名不能为空!";
      }
      else if (password == "")
      {
      msgpassword = "密码不能为空!";
      }
      else
      {
        b=true;
      }return b;
      

  6.   

    上面return true 写在if外面
      

  7.   

    调整后的代码: public string checkuser(string username, string password)
        {                                
          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);
        }
      

  8.   


    //不好意思  应该把 string 改成 void 因为是直接改的,没有编译
    public string checkuser(string username, string password)
      

  9.   

    楼主,你方法是bool类型的,但你最后连个return返回值都没有,它当然报错。既然是bool的,按你的方法就return TRUE