C# lambda vs foreach readability.
source link: https://dev.to/ucavalcante/c-lambda-vs-foreach-readability-4cpg
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
C# lambda vs foreach readability.
Jun 30
・1 min read
Hey guys, recently a receive an feedback that i need to change my code, turn an lambda expression into a foreach loop because its more adherent to clean code, i create this example to explain.
The both versions give me same results, but in my opinion this lambda expression is easy to understand, and easy to write and maintain, and i like to use that.
i receive an recommendation to change that to a for-each loop, like this, to be more clean code adherent.
I really want see other people opinions and arguments about this, and i like lambda expression for me they are very powerful and easy to use.
Discussion (4)
I don't understand,
LINQ is much more readable than for each in anyday.
While foreach is faster than LINQ, its not that noticeable enough.
So the idea is
You want readability over performance = LINQ
You want a slightly faster performance over readiblity = For Each.
CollapseExpand
Hello,
since you asked for opinions.
For me the linq statement Is much easier to understand. Clear structure and short.
When one is used to linq i don‘t know how to write it clearer.
Even when not used to linq it is almost a sentence.
For me, in this case definately pro linq!
Regards
Michael
CollapseExpand
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK