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 illustrating data transfer between controllers using TempData

TempData in ASP.NET Core: Transferring Data Between Controllers

TempData - Transfer data between controllers Ideal for transferring small amounts of data between controllers in ASP.NET MVC. Unlike ViewData and ViewBag, which are specific to a single view, TempData persists for one request cycle. This means the data remains available until it鈥檚 accessed, at which point it鈥檚 automatically removed. 馃憠 Adapted from my original post on LinkedIn .

August 15, 2024 路 1 min 路 59 words 路 Eduardo Potumati
Code snippet illustrating the UseRewriter middleware in ASP.NET Core

Handling Duplicate URLs in ASP.NET MVC: www vs non-www

Concerned about duplicate URLs in ASP.NET MVC? Take care of both www and non-www domains. .NET already provides the correct method to handle them. Using the UseRewriter middleware is the optimal approach. You can use AddRedirectToNonWww() or AddRedirectToWww() for this purpose. 馃憠 Adapted from my original post on LinkedIn .

July 15, 2024 路 1 min 路 50 words 路 Eduardo Potumati
Code snippet demonstrating how to use Reflection to read custom attributes in C#

Accessing Custom Attributes Using Reflection in C#

Accessing Custom Attributes Using Reflection in C# Custom attributes provide a powerful way to attach declarative metadata to your code-whether it鈥檚 on classes, methods, properties, or fields. But how do you actually read that metadata at runtime? This is where Reflection shines. By using the System.Reflection, you can dynamically inspect your code鈥檚 structure and retrieve the information defined within those custom attributes. This functionality is the backbone for creating highly flexible applications, such as automated validation frameworks, custom JSON serializers, or dynamic API routing systems. ...

June 15, 2024 路 1 min 路 116 words 路 Eduardo Potumati
Code snippet demonstrating EF.Functions.Collate for accent-insensitive querying in EF Core

Handling Accents in SQL with EF Core

Have you ever needed to handle accents in SQL? If you are Latin, you have certainly done it many times. And how does it work in EF Core? It鈥檚 easy, you just have to use EF.Functions.Collate! Warning: Overriding case-sensitivity in a query via EF.Functions.Collate (or by calling string.ToLower) can have a very significant impact on your application鈥檚 performance. 馃敆 Know more 馃憠 Adapted from my original post on LinkedIn . ...

March 15, 2024 路 1 min 路 70 words 路 Eduardo Potumati
Code snippet demonstrating the differences between Round, Floor, and Ceiling in C#

Differences Between Round, Floor, and Ceiling in C#

Do you know the differences between Round, Floor, and Ceiling in C#? Round: It follows standard mathematical rounding to the nearest integer. For example, 5.67 => 6, and 5.47 => 5. Floor: It rounds the number down to the nearest integer. For example, 5.67 => 5, and 5.47 => 5. Ceiling: It rounds the number up to the nearest integer. For example, 5.67 => 6, and 5.47 => 6. 馃憠 Adapted from my original post on LinkedIn . ...

February 15, 2024 路 1 min 路 78 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