Why .Select changes Enumerable.Empty to System.Linq.EmptyPartition?

Viewed 1877

Look at this example:

IEnumerable<string> en = Enumerable.Empty<string>(); //{string[0]}
var enSelected = en.Select(id => id);                //{System.Linq.EmptyPartition<string>}
var list = en as IList<object>;                      //{string[0]}
var listSelected = enSelected as IList<object>;      //null

Why using .Select on an empty enumerable changes its type? Could this be a bug in LINQ?

And what is even System.Linq.EmptyPartition? I did not find any documentation about this type and it is also not available directly in the code.

I am using Visual Studio 2017 15.4.2 and this is happening on a Xamarin.iOS project. Could you please test this on your environment so that we can see whether this is specific to my environment?

1 Answers

The declared return value of Select is IEnumerable<T>.

The actual type of the returned object is part of the implementation, and should never concern the user of the API.

Related