Go alternately on your question:
1. Does the item select one item in the collection? -> No, not at all. 'select' returns exactly the same number of elements that are in the collection, but in a different form (if required).
But, yes, it returns a single sequence (/ collection) containing all of these elements (for example, even_sqare in the example below).
eg
int[] even = {2,4}; int[] even_square = even.Select(n=> n*2).ToArray();
o / r
even_square to {4,8} , which is the same in counts (2), but with a different projection, we gave each squares by selecting them.
2. and chooses to smooth the collection a lot (for example, List> ())?
-> yes, but in reality, it looks like a cross connecting with our control.
int[] odd = { 1, 3 }; int[] even = { 2, 4 }; int[] crossjoin = even.SelectMany( n => odd, //combining even with odd (n,o)=>Convert.ToInt32(n.ToString()+o.ToString())//given many selects, decide our projection ).ToArray(); foreach (var item in crossjoin) { Console.WriteLine(item); } Output: 21 23 41 43
Now a million dollar thing:
- Unlike most operators in linq, SelectMany accepts two collections, not one.
- βevenβ is the first set, and odd is the second set, which we passed using lambda, such as βn => oddβ. (here people say that it is smoothed out).
- The third parameter (in the previous statement, the second parameter) is TResult, which gives us an output that is a cross-connection and that is the beauty of SelectMany if we understand this.
- Enjoy the learning.
Suraj yadav
source share