Calling all three functions during use or statement even after returning true as a result

I call three functions in my code where I want to check some of my fields. When I try to work with the code below. It only checks the first value until it gets a false result.

I need something like this if the fisrt function returns true, then it should also call the next function and so on. What can be used instead of Or Operator for this.

    if (IsFieldEmpty(ref txtFactoryName, true, "Required") ||
        IsFieldEmpty(ref txtShortName, true, "Required") ||
        IsFieldEmpty(ref cboGodown, true, "Required"))
    { }

EDIT

public bool IsFieldEmpty(ref TextBox txtControl, Boolean SetErrorProvider,string msgToShowOnError)
{
    ErrorProvider EP = new ErrorProvider();
    if (txtControl.Text == string.Empty)
    {
        EP.SetError(txtControl, msgToShowOnError);
        return true;
    }
    else
    {
        EP.Clear();
        return false;
    }
}

Comment, this method makes excellent use of the ref variable as one of the parameters.

I am checking for confirmation in Submit's event winform.

+3
source share
5

| OR:

 if (IsFieldEmpty(ref txtFactoryName, true, "Required") |
    IsFieldEmpty(ref txtShortName, true, "Required") |
    IsFieldEmpty(ref cboGodown, true, "Required"))
{ }

|| , | .
&& &.

. MSDN.

:

  • 'ref' txtControl, . IsFieldEmpty txtControl. CheckFieldEmpty, .
  • , ErrorProvider , ? () . , , , EP . SetErrorProvider, EP null. O EP.Clear(); Ep.SetErrortxtControl, "");
+10

, :

bool isFactoryNameEmpty = IsFieldEmpty(ref txtFactoryName, true, "Required");
bool isShortNameEmpty = IsFieldEmpty(ref txtShortName, true, "Required");
bool isGodownEmpty = IsFieldEmpty(ref cboGodown, true, "Required");
if (isFactoryNameEmpty || isShortNameEmpty || isGodownEmpty)
{
    // ...
}

( , , , ? IsFieldEmpty - .)

+10

? , , , IsFieldEmpty , . "IsFieldEmpty" .

, /, :

SomeFieldMaintenance(ref txtFactoryName, true, "Required")
SomeFieldMaintenance(ref txtShortName, true, "Required")
SomeFieldMaintenance(ref cboGodown, true, "Required")
if (IsFieldEmpty(txtFactoryname) ||
    IsFieldEmpty(txtShortName) ||
    IsFieldEmpty(cboGodown))
{ }

- .

+6

, , #. , , .

http://johnnycoder.com/blog/2006/08/02/short-circuit-operators-in-c/

| || .

 if (IsFieldEmpty(ref txtFactoryName, true, "Required") |
        IsFieldEmpty(ref txtShortName, true, "Required") |
        IsFieldEmpty(ref cboGodown, true, "Required"))

# http://msdn.microsoft.com/en-us/library/6a71f45d.aspx

|| . http://msdn.microsoft.com/en-us/library/6373h346.aspx

| . http://msdn.microsoft.com/en-us/library/kxszd0kx.aspx

0

, , . . , , , && ||. : " true, ". , false, , , .

0

Source: https://habr.com/ru/post/1741773/


All Articles