Using Array Predicates to simplify searches using ANY Operator

Posted by vishalneeraj-24503 under C# category on | Points: 40 | Views : 428
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.
MessageBox.Show("values can not be empty");

//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