Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Different versions of GetFirstDirectoryFrom
public DirectoryInfo GetFirstDirectoryFrom(params string[] list)
{
foreach (var item in list)
{
var directory = new DirectoryInfo(item);
if (directory.Exists)
return directory;
}
return null;
}
public DirectoryInfo GetFirstDirectoryFrom(params string[] list)
{
return list.Select(l => new DirectoryInfo(l)).Where(d => d.Exists).FirstOrDefault();
}
public DirectoryInfo GetFirstDirectoryFrom(params string[] list)
{
return list.Select(l => new DirectoryInfo(l)).SkipWhile(d => !d.Exists).FirstOrDefault();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.