Using Array Predicates to simplify searches using ANY Operator

vishalneeraj-24503
Posted by vishalneeraj-24503 under C# category on | Points: 40 | Views : 460
Suppose, i have 4 parameters in string array.Obviously,one way to determine if any of parameter values are empty is to iterate through the array,but there is a better way to use the Any operator.

For Example:
string[] input_values = {key1,key2,key3,key4};

//now check if the arguments are empty.
if(Check_IsEmpty(input_values))
{
MessageBox.Show("values can not be empty");
return;
}

//Write a static function to check if the parameter array has any empty values.
private static bool Check_IsEmpty(string[] values)
{
return(values.Any(value => string.IsNullOrEmpty(value.Trim())));
}

Comments or Responses

Login to post response