Today, I came across the All operator in LINQ. This operator returns bool value rather than records after condition is satisfied. The operator will be highly helpful when you need some kind of validation to find unique data. for e.g. Checking the existing email or UserID registered and so on.
Lets Go with a Example to do the Task:
int [] array = { 1,2,3,4,5 };
bool result = array.All(value => value > 2 );
Console.WriteLine(result); // Here it will print False since it will check all the values and // all the values must be grater than 2.
result = array.All(value => value < 6 );
Console.WriteLine(result); // Here it will print True since it will check all the values and // found all values are less than 6.
Hope it helps you!
Lets Go with a Example to do the Task:
int [] array = { 1,2,3,4,5 };
bool result = array.All(value => value > 2 );
Console.WriteLine(result); // Here it will print False since it will check all the values and // all the values must be grater than 2.
result = array.All(value => value < 6 );
Console.WriteLine(result); // Here it will print True since it will check all the values and // found all values are less than 6.
Hope it helps you!
No comments:
Post a Comment