I know HashSets
are inherently unordered, but of course the collection is stored in some order, probably based on the hash buckets. The First
extension method grabs the first element and delivers it to the caller. My question is the following: since the .NET platform is a standard with potentially several implementations, is it written in stone that the First
extension method (from the System.Linq
namespace) should always return the same element for unordered collections like HashSets
as long as that the contents of the collection don't change? I'm imagining things like memory optimisation moving instances around and maybe, if that was not one of the requirements of the standard for First
, that could end up causing different behaviour on different implementations of the platform.
'Can I rely on First
to behave, both now and in the future, no matter on what device?' would be the gist of what I'm asking.