One of my friends just asked me a rather distinctive question. What if I wanted to build a typed collection of SPList objects by passing in a SharePoint web (SPWeb) and a pattern to match the list by (string) into some arbitrary method?
In order to do this, we can presume since the pattern is being passed in as a parameter that in some additional scene it is being constructed and is well-formed. Therefore, we can do a uncomplicated regular expression match leveraging the list title and the pattern. Following, test the result of the match, ensuring that it coordinates to success. We then return the collection if the count is higher than 0, otherwise just return null.
public static List
foreach (SPList list in web.Lists)
if (Regex.Match(list.Title, pattern).Success)
if (tempListCollection.Count > 0)