fork(2) download
  1. using System;
  2. using System.Globalization;
  3. using System.Linq;
  4. using System.Collections.Generic;
  5.  
  6. public class Test
  7. {
  8.  
  9.  
  10. public static void Main()
  11. {
  12. var myTable = new List<Foo>() { new Foo { ColumnValue = "Five" }, new Foo { ColumnValue = "Four" }, new Foo { ColumnValue = "Three" }, new Foo { ColumnValue = "One" } };
  13. string[] prefs = new[] { "One", "Two", "Three" };
  14. string myResult = prefs.Select((pref, index) => new { pref, index })
  15. .Join(myTable, xPref => xPref.pref, x => x.ColumnValue, (xPref, x) => new { xPref, x })
  16. .OrderBy(x => x.xPref.index)
  17. .Select(x => x.x.ColumnValue)
  18. .DefaultIfEmpty("Four")
  19. .First();
  20. Console.Write(myResult);
  21. }
  22.  
  23. public class Foo
  24. {
  25. public string ColumnValue { get; set; }
  26. }
  27. }
Success #stdin #stdout 0.05s 34176KB
stdin
Standard input is empty
stdout
One