code_junkie

How C# Compiler choose SelectMany when translating LINQ expression?

Nov 13th, 2011
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. public static IEnumerable<TResult> SelectMany<TSource, TResult>(
  2. this IEnumerable<TSource> source,
  3. Func<TSource, IEnumerable<TResult>> selector
  4. )
  5.  
  6. public static IEnumerable<TResult> SelectMany<TSource, TCollection, TResult>(
  7. this IEnumerable<TSource> source,
  8. Func<TSource, IEnumerable<TCollection>> collectionSelector,
  9. Func<TSource, TCollection, TResult> resultSelector
  10. )
  11.  
  12. IEnumerable<int> en1 = Enumerable.Range(1, 3);
  13. IEnumerable<double> en2 = new double[] { 1.0, 3.14 };
  14.  
  15. IEnumerable<string> en3 =
  16. from i1 in en1
  17. from i2 in en2
  18. select (i1 * i2).ToString();
  19.  
  20. foreach (var i in en3)
  21. {
  22. Console.WriteLine(i);
  23. }
  24.  
  25. en1.SelectMany<int, double, string>(delegate (int i1) {
  26. return en2;
  27. }, delegate (int i1, double i2) {
  28. double CS$0$0000 = i1 * i2return CS$0$0000.ToString();
  29. })
  30.  
  31. IEnumerable<int> en4 =
  32. from i1 in en1
  33. from i2 in Enumerable.Range(0, i1)
  34. select i2;
  35.  
  36. en1.SelectMany<int, int, int>(delegate (int i1) {
  37. return Enumerable.Range(0, i1);
  38. }, delegate (int i1, int i2) {
  39. return i2;
  40. })
  41.  
  42. public IEnumerable<string> Example(IEnumerable<IEnumerable<string>> enumerable) {
  43. return enumerable.SelectMany(x => x);
  44. }
  45.  
  46. var orders = Customers.SelectMany(c => c.Orders)
Add Comment
Please, Sign In to add comment