Q:

How should I write a FindClosestMatching function?

Of all objects matching a condition, find the one closest to a position. Supposedly a very common problem. The current code looks like this:
protected Foo FindClosestFooMatching (Vec pos, Func<Foo, bool> matches)
{
    float bestDist = float.MaxValue;
    Foo bestFoo = null;

    foreach (Foo foo in AllFoos()) {
        if (matches (foo)) {
            float dist = pos.Dist (foo.Center);
            if (dist <= bestDist) {
                bestDist = dist;
                bestFoo = foo;
            }
        }
    }
    return bestFoo;
}

I'm thinking of several ways to refactor this code, but failed to find a really nice one yet. If you've got a minute, give it a shot.  :-)
Edit: Regarding Eric's questions. It's a standard 3D space with Euclidian metric (= fast). Point clustering and junk query likelihood is unknown.

A:

Can't compile right now, but I hope this does the job.
var foos = AllFoos().Where (x => matches (x));
return foos.OrderBy (x => pos.Dist (x.Center)).FirstOrDefault ();

The important point to notice here is that every operation, including OrderBy, is subject to deferred execution, so the performance should be ok.
This would be a nicer looking solution:
var res = from foo in AllFoos()
    where matches (foo)
    orderby pos.Dist (foo.Center)
    select foo;
return res.FirstOrDefault ();

Edit: I found this question to be a valuable source in this issue. Since OrderBy actually orders the whole list first, it's of course slow (as Eric said, O(n log n). A better solution would be to use Aggregate or Jon Skeet's propsed MinBy extension (see above link for examples).
I actually love the MoreLinq solution, as it reduces the code to:
return World.AllNodes
    .Where (x => matches (x.T))
    .MinBy (x => pos.DistSq (x.T.Volume.Center));

