Q:

LINQ generic function for find in a enumerable

I need to create a method that with a generic enumerable of type T it finds inside it using in the where the term i specify
public static object findInList<T>(T[] list, string searchTerm, string seachIndex)
{
    string normalized1 = Regex.Replace(seachIndex, @"\s", "");
    var sel = (from l in list
                     where normalized1.Equals([the item i want to compare])
                     select l).FirstOrDefault();
    return sel ;
}

i need this because i want to create a generic method for search an item in my array that i can customize in some way (below the code in its original way)
[...]
string normalized1 = Regex.Replace(seachIndex, @"\s", "");
sel = (from l in list
        where normalized1.Equals(l.Ordine)
        select l).FirstOrDefault();
[...]

[edit]
Thanks to Servy for the answer. For full index of this answer i add here how to call this method
Func<XXX, string> keySelector = delegate(XXX b) { return b.XX; };
var return = findInList<XXX>(list, keySelector, seachIndex);

Where XXX is the type of the list and XX is the property you want to compare for the search

A:

What you need here is for your method to accept a selector, some function that determines what you should compare for each of your objects.
public static T findInList<T>(
    IEnumerable<T> sequence,
    Func<T, string> keySelector,
    string searchTerm,
    string seachIndex)
{
    string normalized1 = Regex.Replace(seachIndex, @"\s", "");
    return (from l in sequence
            where normalized1.Equals(keySelector(l))
            select l).FirstOrDefault();
}

You can also return a T instead of an object, since you know that that's what it is, ensuring that the caller doesn't need to cast it back to what it is.  You can accept an IEnumerable instead of an array since you're only ever iterating it, thus giving the caller more flexibility while still letting you do everything that you need to do.

