C#: Get a list of every value for a given key in a set of dictionaries?

Posted by Rosarch on Stack Overflow See other posts from Stack Overflow or by Rosarch
Published on 2010-03-18T19:46:07Z Indexed on 2010/03/18 19:51 UTC
Read the original article Hit count: 297

How can I write this code more cleanly/concisely?

    /// <summary>
    /// Creates a set of valid URIs.
    /// </summary>
    /// <param name="levelVariantURIDicts">A collection of dictionaries of the form:
    ///                                     dict["filePath"] == theFilePath </param>
    /// <returns></returns>
    private ICollection<string> URIsOfDicts(ICollection<IDictionary<string, string>> levelVariantURIDicts)
    {
        ICollection<string> result = new HashSet<string>();
        foreach (IDictionary<string, string> dict in levelVariantURIDicts)
        {
            result.Add(dict["filePath"]);
        }
        return result;
    }

© Stack Overflow or respective owner

Related posts about c#

Related posts about coding-style