Link to home
Start Free TrialLog in
Avatar of ukerandi
ukerandiFlag for United Kingdom of Great Britain and Northern Ireland

asked on

C# Function

Hi,
I need to the following code to custom function.Any idea appreciate
 if (TxtPostcode.Text == null && string.IsNullOrWhiteSpace(TxtPostcode.Text))
                    {
                        validate = 1;
                    }

                    if (TxtDestinationName.Text == null && string.IsNullOrWhiteSpace(TxtDestinationName.Text))
                    {
                        validate = 1;
                    }

                    if (TxtDestinationDescription.Text == null && string.IsNullOrWhiteSpace(TxtDestinationDescription.Text))
                    {
                        validate = 1;
                    }

Open in new window

SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@it_saige - You are returning int NOT boolean.
@Pawan,

I did not say that I was returning a boolean.  The result of the IsNullOrWhiteSpace method is a boolean.

The preceeding examples were using a ternary operation to return a 1 or a 0 based upon that boolean result.  I am stating that those examples could be simplified further by converting the boolean result of IsNullOrWhiteSpace to an integer.

-saige-
Ohh that way .. cool :)
Avatar of ukerandi

ASKER

Hi Guy,Thanks i understand the logic in the Function but
issue is i can't use if condition for 4 or 5 time.
Any other better way to validate this
int ValidatePostcode = validate(TxtPostcode.Text);
int ValidateDestinationName = validate(TxtDestinationName.Text);
int DestinationDescription = validate(TxtDestinationDescription.Text);
IF(ValidatePostcode=0)
{

}


IF(ValidateDestinationName=0)
{

}


IF(DestinationDescription=0)
{

}
I have wrote a program using array to validate.It's working fine.
then for each() loop help me to validate.
thanks Guy
thax