Original description:
I am dealing with single threaded synchronous logic and I started observing some differences in output depending on whether I run code in debug or release mode. I started wondering where the lack of determinism can come from. I make a heavy use of LINQ, so I thought maybe collections like HashSet, which don't have inherent ordering, cause the issue?
If they aren't deterministic that would have some interesting consequences, like, for instance, First() would be really a random element with potentially some non-obvious probability distribution...
Further explanations:
I don't care about criterion of ordering. Specifically I don't care if it's insertion order. I only ask if the ordering is set and shared between order-sensitive operations on HashSet without any changes.
Example for illustration purposes:
I have a method, not relying on any state, that creates a HashSet. It puts some elements in and returns First().
Do I have guarantee that it will always be same element between method calls?
Will it be same element when the whole application is terminated and executed again?
If answer to any of these is no, that would mean to me, that from programmers perspective there is not determinism for LINQ order-sensitive operations on HashSet. Once again, I don't have requirement to know ordering criterion (comparer used internally).