- Home /
[Solved]List.FindIndex error C#
Hi, I am trying to perfom this code but it keeps throwing me this error. I looked it up and didnt find nothing useful.
public int getBlockIndex(Vector3 pos){
int index = ChunkBlocks.FindIndex(pos);
return index;
}
Error:
Assets/Chunk.cs(44,49): error CS1502: The best overloaded method match for `System.Collections.Generic.List<UnityEngine.Vector3>.FindIndex(System.Predicate<UnityEngine.Vector3>)' has some invalid arguments
And
Assets/Chunk.cs(44,49): error CS1503: Argument `#1' cannot convert `UnityEngine.Vector3' expression to type `System.Predicate<UnityEngine.Vector3>'
Any ideas, Suggestions fixies or explanation why this is not working? As far as i know is something related to delgates which i dont know what they are, I tried to fix it but i couldnt.
Thanks.
Answer by whydoidoit · Feb 24, 2014 at 07:32 AM
FindIndex takes a predicate like this:
int index = ChunkBlocks.FindIndex(d=>d == pos);
I think you really want IndexOf right?
Thanks, It worked, but could you explain to me why is the d=>d == pos is needed. And how to apply it to differents FinIndex?
EDIT: Yep now i did it with IndexOf, Thanks for the advice!!
Your answer
Follow this Question
Related Questions
Null reference exception: Object reference not set to an instance of an object 3 Answers
Multiple Cars not working 1 Answer
Need help with ArgumentOutOfRange Error 1 Answer
How can I use foreach and a list of vector3s to reset the positions of all child objects? 1 Answer
Cannot convert float to int when only using floats (C#) 3 Answers