Cannot convert UnityEngine.GameObject to UnityEngine.GameObject

I’m using Linq.Where to filter objects in a list to find a object with a specific location like so:

Vector3 targetPosition = new Vector3(1,2,3) ;

GameObject go = TerrainObjs.Where ( obj => obj.transform.position == targetPosition ) ;

results in the error: "error CS0029: Cannot implicitly convert type ‘System.Collections.Generic.IEnumerable[UnityEngine.GameObject]’ to ‘UnityEngine.GameObject’ "

I’m not sure if/what i did wrong, or a way around this. Built-in conversions don’t work and that’s pretty much the limit of my knowledge. I’m a bit of a noob with Linq.Where and I’m trying to clean up my code with more compact techniques.

Where returns a list of elements, not a single GameObject as you expect.

IEnumerable<GameObject> gos = TerrainObjs.Where(obj => obj.transform.position == targetPosition);
foreach (GameObject go in gos)
    ; // do what you need with go

On the other hand, you should not compare positions with “==”. Doing it that way you will have problems with float precision (two elements in the same place can have slightly different numeric representations). You should subtract vectors and check magnitude (distance).