Empty Sequence in LINQ
c#, linq
Solution
You can use this when you want to quickly create an `IEnumerable<T>` this way you don't have to create a reference to a new `List<T>` and take advantage of the yield keyword.
List<string[]> namesList =
new List<string[]> { names1, names2, names3 };
// Only include arrays that have four or more elements
IEnumerable<string> allNames =
namesList.Aggregate(Enumerable.Empty<string>(),
(current, next) => next.Length > 3 ? current.Union(next) : current);
Note the use of Union because it is not a List you can not call Add method, but you could call Union on an `IEnumerable`
Problem
I recently faced an interview question related to LINQ. What is the use of empty sequence?.He asked "if i suppose to ask you to use the one,where do you fit it?" ``` public static IEnumerable<TResult> Empty<TResult>() { yield break; } ``` I did not answer it.Help is appreciated.