Created
June 28, 2012 17:37
-
-
Save ChrisMissal/3012752 to your computer and use it in GitHub Desktop.
Different versions of GetFirstDirectoryFrom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public DirectoryInfo GetFirstDirectoryFrom(params string[] list) | |
{ | |
foreach (var item in list) | |
{ | |
var directory = new DirectoryInfo(item); | |
if (directory.Exists) | |
return directory; | |
} | |
return null; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public DirectoryInfo GetFirstDirectoryFrom(params string[] list) | |
{ | |
return list.Select(l => new DirectoryInfo(l)).Where(d => d.Exists).FirstOrDefault(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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