fork(3) download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. public class Test
  6. {
  7. public static void Main()
  8. {
  9. List<string> bunchOfStrings = new List<string>();
  10. bunchOfStrings.Add("This should not be at the top");
  11. bunchOfStrings.Add("This should not be at the top either");
  12. bunchOfStrings.Add("This should also not be at the top");
  13. bunchOfStrings.Add("This *SHOULD be at the top");
  14. bunchOfStrings.Add("This should not be at the top");
  15. bunchOfStrings.Add("This should be *somewhere close to the top");
  16.  
  17. foreach (var str in bunchOfStrings.OrderBy(x => {
  18. var index = x.IndexOf("*");
  19. return index < 0 ? 9999 : index;
  20. }))
  21. {
  22. Console.WriteLine(str);
  23. }
  24. }
  25. }
Success #stdin #stdout 0.06s 34224KB
stdin
Standard input is empty
stdout
This *SHOULD be at the top
This should be *somewhere close to the top
This should not be at the top
This should not be at the top either
This should also not be at the top
This should not be at the top