I will not talk about the correctness of your code, but I would like to be able to explain the general rule In Software Develpment, performance loss is inversely related to the level of abstraction. In this case, itβs quite normal that foreach is faster than LINQ (which is more abstract). If you compare it with the classics for (for (int i: i ++ l, etc.)), it will be faster than foreach. Access to an object assumes that the interface is slower than access to a specific object: the interface is already a very small level of abstraction. The code you write will be as fast as "close" to machine code, but, of course, it will be less readable and convenient. The point is how to find the right level of abstraction for what we are developing, taking into account the performance and readability of the code.
You do not need an MVC template to create a one-page website that shows a table on a repeater :-)
Massimiliano peloso
source share