分配布尔值时出错

use*_*521 2 c#

我在分配值时遇到错误.

我的代码是:

    protected bool ValidateProfile()
    {
       bool blnFirstName = false;
       bool blnLastName = false;
       bool blnEMail = false;

      //(error on line below: "The left-hand side of an assignment must be a variable, property or indexer")
       ValidateProfile() = false;


   if txtFName != ""
      blnFName = true;

   if txtLName != ""
      blnLName = true;

   if txtEMail != ""
      blnEMail = true;

   if (blnFName) && (blnLName) && (blnEMail))
     ValidateProfile = true;

    }
Run Code Online (Sandbox Code Playgroud)

如何为ValidateProfile分配布尔值?

谢谢

Joh*_*ers 7

你要

return false;
Run Code Online (Sandbox Code Playgroud)

在C#中,我们不为函数名赋值,以便返回值.


如果要在从方法返回的不同时间点设置返回值,则应该执行以下操作:

bool retVal; // Defaults to false

if (condition)
    retVal = true;

if (otherCondition)
    retVal = false;

if (thirdCondition)
    retVal = true;

return retVal;
Run Code Online (Sandbox Code Playgroud)