In the below example when I donot use .ToList()
in the Line - var b = a.SelectMany(x => a.Select(y => { ans.Add(new Tuple<int, int>(x, y)); return false; })).ToList();
The Count of ans
is 0
Can someone explain what exactly happening here with and without .ToList();
public void selectAll()
{
var ans = new List<Tuple<int, int>>();
var a = new List<int>()
{
1,2,3
};
var b = a.SelectMany(x => a.Select(y => { ans.Add(new Tuple<int, int>(x, y)); return false; })).ToList();
foreach (var item in ans)
{
Console.WriteLine($"{item.Item1},{item.Item2}");
}
}