A comparison table or code snippet demonstrating List vs IEnumerable in C#

List<T> or IEnumerable<T> in C#: Which one to choose?

That classic question: List<T> or IEnumerable<T> in C#? Straight to the point: IEnumerable<T>: when you only need forward iteration. It also works with deferred execution, the basis of LINQ and ideal for handling large amounts of data without loading everything into memory. ICollection<T>: in addition to iteration, it allows you to add, remove, and count items, but without index access. IList<T>: includes everything from ICollection<T>, plus index-based access and the ability to insert/remove at specific positions. List<T>: the concrete implementation of IList<T>, the class you usually use to instantiate a list. Why does this matter? Whenever possible, use the minimal required interface. Clear contracts reduce coupling and make your code more flexible and easier to maintain. ...

November 15, 2025 · 1 min · 125 words · Eduardo Potumati
An example showing implicit operator conversions in C# with potential pitfalls

Implicit Operators in C#: Convenience vs. Clarity

In C#, implicit operators enable automatic type conversions without the need for explicit casting. This functionality not only enhances code readability but also boosts development agility while safeguarding against runtime conversion exceptions. However, be careful. While implicit conversions offer convenience, excessive usage can potentially compromise code clarity. It’s essential to tread carefully as an overreliance on implicit conversions may obscure the precise moments and locations where conversions occur. 👉 Adapted from my original post on LinkedIn . ...

March 22, 2025 · 1 min · 77 words · Eduardo Potumati
A diagram or code snippet illustrating the Dependency Inversion Principle

Dependency Inversion (D) in SOLID: Why Is It So Important?

Dependency Inversion (D) in SOLID: Why Is It So Important? The Dependency Inversion Principle (D) reminds us that “high-level modules should not depend on low-level modules; both should depend on abstractions.” This means clients (code consuming functionalities) should rely on interfaces or abstractions, not concrete implementations. This practice reduces coupling, simplifies changes, and makes code more testable. For example, instead of directly coupling a notification service to a concrete class like EmailSender, use an interface such as IEmailSender. This allows you to easily swap implementations (e.g., SMTPClient, API service, message queue, etc) without modifying the client. ...

December 15, 2024 · 1 min · 124 words · Eduardo Potumati
A code comparison showing a foreach loop converted into a LINQ expression

Convert a foreach Loop to LINQ

Convert a foreach loop to LINQ LINQ transforms a query into a first-class language construct in C#. It can reduce the amount of code, enhance readability, and enable similar query expression patterns across different data sources. 👉 Adapted from my original post on LinkedIn .

November 15, 2024 · 1 min · 45 words · Eduardo Potumati
Code snippet demonstrating how to compare two numbers using Math.Abs in C#

Comparing Numbers with Tolerance in C#

Comparing Numbers with Tolerance in C# Sometimes, when comparing two numbers in C#, you may want to allow for a tolerance or interval in the comparison. Instead of manually adding, subtracting, and comparing the values, you can use Math.Abs on the difference between the two numbers to check if the result falls within your acceptable range. 👉 Adapted from my original post on LinkedIn .

September 15, 2024 · 1 min · 65 words · Eduardo Potumati
Code snippet demonstrating pattern matching to protect against nulls in C#

Pattern Matching in C#: Getting Protected from Nulls

Pattern Matching: Get Protected from Nulls C# pattern matching provides a substantially more concise syntax for testing expressions and taking decisive action when an expression matches. By leveraging these structural features, you can gracefully bundle type checks, variable declarations, and null validations into a single, highly readable statement-significantly reducing boilerplate code and the risk of unexpected NullReferenceExceptions. 👉 Adapted from my original post on LinkedIn .

May 15, 2024 · 1 min · 66 words · Eduardo Potumati
Code diagram comparing struct and class memory allocation in .NET

Struct or Class: When to Use Which in C#

Struct or class? Most types in a framework should be classes, but there are some situations in which the characteristics of a value type make it more appropriate to use structs. Here are some things to consider: 👍 If your instances are small and short-lived, or commonly embedded in other objects, consider using a struct. 👎 However, be cautious when defining a struct. Only use it if the type represents a single value, is immutable, has an instance size under 16 bytes, and will not need to be boxed frequently. ...

December 15, 2023 · 1 min · 125 words · Eduardo Potumati