C# – Replacing foreach with LINQ query


I have the following code in one of my methods:

foreach (var s in vars)
    foreach (var type in statusList)
        if (type.Id == s)
            Add(new NameValuePair(type.Id, type.Text));

This seems sort of ineffective to me, and I was wondering if there was a way to substitute at least one of the foreaches wih a LINQ query. Any suggestions?

EDIT: vars is an array of strings and the Add method adds an item to a CSLA NameValueList.

Best Solution


var types =
    from s in vars
    let type = (
        from tp in statusList
        where tp.Id == s ).FirstOrDefault()
    where type != null
    select new NameValuePair(type.Id, type.Text)