public static IEnumerable GetCDFolders(string root) { foreach(string name in System.IO.Directory.GetDirectories(root).AsEnumerable()) { string name2 = name.Substring(root.Length+1); switch(name2) { case "CD1": case "CD2": case "CD3": case "CD4": case "CD5": case "CD6": yield return name2; break; } } } //code which calls that function.. if(GetCDFolders(folder).Count() > 0) { foreach(string fol in GetCDFolders(folder)) { //do the magic here } } else { //do stuff if count is equal to zero or smaller } the first call happens to in the if statement, which if it's equal to 0 won't be much, however, if it's bigger than 0, then that directory list from the getcdfolder's function is going to run through all the results, no? the second call happens in the foreach statement.. If there was a way to say foreach(string fol in GetCDFolders(folder)) { //do magic here } else { //do stuff if count is equal to or smaller than zero } For example, if I was trying to get the list from a network share, then the time actually becomes an issue..Because it has to connect to the other machine to get the list, twice.