Ali Hamza Ansari

Ali Hamza Ansari

Meet Ali, a talented .NET developer from Pakistan. Besides blogging, Ali works for a range of international customers doing everything from C# to Azure.

39 posts
Hidden Costs of Boxing in C#: How to Detect and Avoid Them

C# Boxing and Unboxing are vital players in the performance of an application. However, they are often overlooked. They involve heap allocations that bring a penalty due to their accessing mechanism. In today's post, we will unfold Boxing and Unboxing in detail, study how they are costly to ...

Expression Trees in C#: Building Dynamic LINQ Queries at Runtime

Tired of endless if-else blocks just to build queries? What if your LINQ queries could write themselves at runtime? Today, we will unfold expression trees, which can be used to create dynamic queries at runtime. I will show how to use expression trees in your project and understand their advantages ...

Demystifying async void in C#: Why It's Dangerous and When It's Okay

Async operations are an integral part of any application. In C#, mostly asynchronous methods return Task or Task<T>, but there's also the odd case of async void. We know void is for synchronous operations, so why does C# even allow async void? I will dissect ...

Visualizing LINQ Queries with LINQPad: Boost Your EF Core Debugging

Ever feel exhausted debugging a complex EF Core query? Do you wonder what went wrong in the EF Core LINQ query spaghetti that hinders the results? At one end, EF Core and LINQ accelerate the development speed and make it easy to communicate with a database. However, its intermediate results ...

Mastering Incremental Source Generators in C#: A Complete Guide with Example

In the Previous blog, I discussed source generators. .NET has introduced an improved version of a source generator, called Incremental Source Generator. The new type generates code faster and reduces the code, improving readability. In this post, I will introduce the new type of source generator and compare it to ...

How I Reduced API Response Time by 70% in a Large .NET Project

Slow APIs hurt users' experience and the owners' pocket. Users become disappointed, and the server costs more if APIs are not up to standard in large projects. I also faced a similar issue in my project. However, I cut down the performance overhead marginally. This article breaks down ...

Implementing Audit Logs in EF Core Without Polluting Your Entities

Most modern applications require the historical audit logging of changes made to database entities. The audit log provides you with insights into all changes made, including their timestamps and the users responsible for those changes. The logs ensure transparency, allowing stakeholders to observe what changes were made to business-critical data, ...

Exploring Source Generators in C#: Real-World Examples

Tired of writing the same class scaffolding over and over? Annoyed by how much time you spend on "glue code" instead of actual features? You're not alone. Imagine if the C# compiler does this on your behalf every time, perfectly. Let me introduce you to C# ...

Using Result<T> or OneOf<T> for Better Error Handling in .NET

Are you tired of debugging vague errors or overusing try-catch? Traditional exception-based workflows can be messy, highly compromising code readability and maintainability. In this post, I will introduce you to Result<T> and OneOf<T>. Two powerful patterns that make success and failure contracts explicit. Whether ...