Function to find a certificate in either the user or the machine store I wanted a function that would return a certificate, given its serial number, regardless of which store it is in. It has to do almost the same exact thing but twice (once for each store). To keep it encapsulated I wrote the "same thing" bit as a lambda, sort of like a Javascript programmer might.

public X509Certificate FindClientCertificate(string serialNumber)
{
    Func&lt;StoreLocation, X509Certificate&gt; find = (location) =&gt;
    {
        X509Store store = new X509Store(location);
        store.Open(OpenFlags.OpenExistingOnly);
        IEnumerable certs = store.Certificates.Find(X509FindType.FindBySerialNumber, serialNumber, true);
        return certs.OfType&lt;X509Certificate&gt;().FirstOrDefault();
    };
    return find(StoreLocation.CurrentUser) ?? find(StoreLocation.LocalMachine);
}


Questions:


Is the purpose and implementation of this function easier to read with the lambda expression? Or is this utterly confusing?
Is there any performance loss or other sort of hidden cost of using a lambda expression as a nested function?


I'm looking forward to C#7 local functions :)
I agree with @JanDotNet that by using a separate method you will gain readability but that's just my subective view. 



As you are asking about C#7 stuff I assume that you will use .NET >= 4.6. Starting with .NET 4.6 the X509Store implements IDisposable hence you should enclose the using of the X509Store inside a using block.  

Instead of using a concrete type you could use the var type  to declare your variables.  

This would result in  

public X509Certificate FindClientCertificate(string serialNumber)
{
    return Find(serialNumber, StoreLocation.CurrentUser) ?? Find(serialNumber, StoreLocation.LocalMachine);
}
private static X509Certificate Find(string serialNumber, StoreLocation location)
{
    using (var store = new X509Store(location))
    {
        store.Open(OpenFlags.OpenExistingOnly);
        var certs = store.Certificates.Find(X509FindType.FindBySerialNumber, serialNumber, true);
        return certs.OfType&lt;X509Certificate&gt;().FirstOrDefault();
    }
}