0

I want to check if a position exists in a list containing positions.

    private bool PositionExists(List<Vector2> positions, Vector2 position)
    {
        return positions.Exists(position);
    }

This throws me the error

CS1503 C# Argument 1: cannot convert from "Project.Vector2" to "System.Predicate Project.Vector2"

Can I fix this or do I have to use Linq

return positions.Any(currentPos => currentPos == position);
Question3r
  • 2,774
  • 4
  • 38
  • 90
  • You might want to put a lambda in your Exists, like `p => p == position`, but you'll end up with the same as Any, so you might as well just use that. Or write a predicate function... – schwaber May 03 '18 at 18:53
  • So using `Any` but be better anyway? – Question3r May 03 '18 at 18:55
  • 1
    I will refer to this answer: https://stackoverflow.com/questions/879391/linq-any-vs-exists-whats-the-difference#879533 Essentially they are the same - at least if you use the lambda notation. – schwaber May 03 '18 at 18:57

1 Answers1

3

Did you mean...

return positions.Contains(position);
Black Light
  • 2,160
  • 4
  • 24
  • 43