fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. public class Test
  6. {
  7. static IEnumerable<string> Filter(IEnumerable<string> files, string query) {
  8. var lowerQuery = query.ToLower();
  9. var hasNew = lowerQuery.StartsWith("new");
  10. return files
  11. .Where(f =>
  12. f.ToLower().Contains(lowerQuery)
  13. && (hasNew || !f.ToLower().StartsWith("new"))
  14. );
  15. }
  16. public static void Main()
  17. {
  18. var data = new[] {"NewFile1", "NewFile2", "File1", "File2", "Newfoundland"};
  19. foreach (var s in Filter(data, "file")) {
  20. Console.Write("{0} ", s);
  21. }
  22. Console.WriteLine();
  23. foreach (var s in Filter(data, "newf")) {
  24. Console.Write("{0} ", s);
  25. }
  26. Console.WriteLine();
  27. }
  28. }
Success #stdin #stdout 0.01s 131648KB
stdin
Standard input is empty
stdout
File1 File2 
NewFile1 NewFile2 Newfoundland