PageRenderTime 104ms CodeModel.GetById 35ms RepoModel.GetById 0ms app.codeStats 0ms

/mcs/tests/gtest-linq-10.cs

https://bitbucket.org/steenlund/mono-2.6.7-for-amiga
C# | 69 lines | 47 code | 17 blank | 5 comment | 14 complexity | 08b513613318027cf2b49885bc3fcbb5 MD5 | raw file
Possible License(s): LGPL-2.0, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, GPL-2.0, LGPL-2.1
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. class DataA
  5. {
  6. public int Key;
  7. public string Text;
  8. }
  9. class DataB
  10. {
  11. public int Key;
  12. public string Value;
  13. }
  14. class GroupJoin
  15. {
  16. public static int Main ()
  17. {
  18. DataA[] d1 = new DataA[] { new DataA () { Key = 1, Text = "Foo" }};
  19. DataB[] d2 = new DataB[] { new DataB () { Key = 2, Value = "Second" }};
  20. var e = from a in d1
  21. join b in d2 on a.Key equals b.Key into ab
  22. from x in ab.DefaultIfEmpty ()
  23. select new { a = x == default (DataB) ? "<empty>" : x.Value, b = a.Text };
  24. var res = e.ToList ();
  25. if (res.Count != 1)
  26. return 1;
  27. if (res [0].a != "<empty>")
  28. return 2;
  29. if (res [0].b != "Foo")
  30. return 3;
  31. // Explicitly typed
  32. e = from a in d1
  33. join DataB b in d2 on a.Key equals b.Key into ab
  34. from x in ab.DefaultIfEmpty ()
  35. select new { a = x == default (DataB) ? "<empty>" : x.Value, b = a.Text };
  36. foreach (var o in e)
  37. Console.WriteLine (o);
  38. res = e.ToList ();
  39. if (res.Count != 1)
  40. return 10;
  41. if (res [0].a != "<empty>")
  42. return 11;
  43. if (res [0].b != "Foo")
  44. return 12;
  45. // FIXME: Used same name
  46. //var e2 = from a in d1
  47. // join a in d2 on a.Key equals a.Key into ab
  48. // select a;
  49. Console.WriteLine ("OK");
  50. return 0;
  51. }
  52. }