Answer the question
In order to leave comments, you need to log in
Why doesn't a similar implementation via LINQ query work?
Hello.
I don’t seem to understand something about Predicate, but I really don’t catch up with why this code works:
for (int i = 0; i < Beads.Count; i++)
if (Vector3.Distance(Beads[i].position, pos) < 0.1f)
return false;
return true;
return Beads.Any(n => Vector3.Distance(n.position, pos) < 0.1f);
Answer the question
In order to leave comments, you need to log in
// Аналогично циклу с использованием Any
return !Beads.Any(n => Vector3.Distance(n.position, pos) < 0.1f);
// Можно с использованием All
return Beads.All(n => !Vector3.Distance(n.position, pos) < 0.1f);
false
, returns if the condition is met at least once. Any
in this case will return true
. So you need to apply inversion. You can also rewrite the operation using the All
.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question