I got following query
IEnumerable<string> values = from first in goodOrdered
join second in badOrdered on first.ToLower() equals
second.ToLower()
select second;
Currently my tests show that end result is actually goodOrdered, like I want it. Can I expect that to always be true or I should provide an order by statement that will force to keep goodOrdered order ( it will make query more complex, because goodOrdered can look like 1, 9, 2, 7, 6)?
Yes, it does. According to the MSDN documentation:
Join preserves the order of the elements of outer, and for each of these elements, the order of the matching elements of inner.
Of course, if it was not specified in the documentation it would be an entirely different matter. Another issue you may want to consider is developers who will be responsible for maintaining the code, and whether you would expect them to know/remember that Join's contract includes preserving order of the outer sequence...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With