Directory.EnumerateFiles read order
arrays, c#, file, ienumerable, indexing
Solution
As far as I can tell, it's not documented - therefore even if you can spot a pattern, you shouldn't rely on it. It may depend on the version of .NET, or the version of the operating system, or simply change between service packs. Instead, if you need some specific order, you should sort it yourself. Of course that unfortunately requires finding all the file names before processing them, but it will give you consistency.
To be honest though, it sounds like you've got a very fragile data model. You haven't really told us enough about what you're doing to fix it, but using the integer index of a file within the results of `Directory.EnumerateFiles` is surely not the best approach.
If you used the file name instead of the index, that would allow you to process files as you read them, potentially - but there may well be even better approaches, depending on what you're trying to do. Using the name should still be reasonably cheap - it'll just be a single string reference instead of an integer, and even if it's used in multiple places, it'll be several references to the same string object.
Problem
What is the default read order for the `Directory.EnumerateFiles` method? Is it consistent? In my experience so far it seems to be by the date the files were created but I haven't been able to find confirmation of this. Reason I ask is because part of a program I am working on loads binary files from directories into objects which are in turn loaded into arrays. These objects reference each other by arrays of indices, meaning the order they are loaded into their arrays needs to remain consistent (to avoid shifting indices). While I'm here, I have another minor question. When files are deleted, it obviously changes the indices of the files loaded into arrays no matter what I do. Any suggestions for avoiding this problem? I've avoided using a dictionary up until now due to worries about storage (would rather not be storing arrays of textual keys if I can avoid it) but if it's the only feasible approach, I may have to implement it anyway. EDIT: After the excellent tips from your answers, I've refactored to a dictionary approach using the names of the files. The performance impact has been fairly negligible and the readability and maintainability are both vastly improved so it's worked out quite well.