c# - TakeWhile() function is not working properly with Boolean value. -
according below code snippet when true value not matched in fruit array result value should hold values of array. takewhile() function not adding not matched value result list below code snippet.
bool[] fruits = { false, false, false, false, false, false}; var query = fruits.takewhile(fruit => fruit.equals(true));
where when string works:
string[] fruits = { "apple", "banana", "mango", "orange", "passionfruit", "grape" }; ienumerable<string> query = fruits.takewhile(fruit => string.compare("orange", fruit, true) != 0);
is there way can make takewhile() function behave equal array of string when there array of bool values?
what looking is:
var query = fruits.takewhile(fruit => !fruit.equals(true));
it logical... take elements of fruit
while are...
you wrote "equal
true
"...i wrote "not equal
true
"
string.compare("orange", fruit, true) != 0
means if "orange" different fruit
true
, else false
Comments
Post a Comment