In C#/VB.NET/.NET, which loop runs faster, for or foreach?
for
foreach
Ever since I read that a for loop works faster than a foreach
It probably depends on the type of collection you are enumerating and the implementation of its indexer. In general though, using foreach is likely to be a better approach.
Also, it'll work with any IEnumerable - not just things with indexers.
IEnumerable