How does linq Any() works internally

c#, linq

Solution

All of the LINQ methods are actually extension methods of `IEnumerable`.

Here is what Reflector decompiles the `Any` LINQ method to:

public static bool Any<TSource>(this IEnumerable<TSource> source, 
                                Func<TSource, bool> predicate)
{
    if (source == null)
    {
        throw Error.ArgumentNull("source");
    }
    if (predicate == null)
    {
        throw Error.ArgumentNull("predicate");
    }
    foreach (TSource local in source)
    {
        if (predicate(local))
        {
            return true;
        }
    }
    return false;
}

Problem

I'm intrigued to know how someCollection.Any() internally works. how can I see this code ?

Original source