Alternatives for Common Anti-Patterns

Anti-patterns have a negative impact on the maintainability of a software systems. These are nothing but a poor solution to recurring design problem and generally occurs when developers unknowingly introduce them while designing and implementing the features to the product.

So in this blog we will try to replace the negative aspects of the anti-pattern with something that will give a positive outcome.

Using FirstOrDefault and Any

Try avoiding to call Any() or Count > 0 before foreach() such as in the following code:

Prefer IEnumerable<>.Any to List<>.Exists

When manipulating IEnumerable, prefer to use Any() instead of ToList().Exists(). Check out the following code:

Becomes:

Read more:https://tudip.com/blog-post/alternatives-for-common-anti-patterns/

--

--