public
Created

Different versions of GetFirstDirectoryFrom

  • Download Gist
GetFirstDirectoryFrom1.cs
C#
1 2 3 4 5 6 7 8 9 10
public DirectoryInfo GetFirstDirectoryFrom(params string[] list)
{
foreach (var item in list)
{
var directory = new DirectoryInfo(item);
if (directory.Exists)
return directory;
}
return null;
}
GetFirstDirectoryFrom2.cs
C#
1 2 3 4
public DirectoryInfo GetFirstDirectoryFrom(params string[] list)
{
return list.Select(l => new DirectoryInfo(l)).Where(d => d.Exists).FirstOrDefault();
}
GetFirstDirectoryFrom3.cs
C#
1 2 3 4
public DirectoryInfo GetFirstDirectoryFrom(params string[] list)
{
return list.Select(l => new DirectoryInfo(l)).SkipWhile(d => !d.Exists).FirstOrDefault();
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.