Paweł Łukaszuk

Tips, tricks and quirks in .NET

That simple LINQ refactoring your IDE suggests could make your code five times slower. Discover which common .NET 'optimizations' to avoid.

Tips, tricks and quirks in .NET
#1about 2 minutes

The surprising internal structure of generic lists

The generic `List<T>` in .NET is not a linked list but is implemented as a resizable array, which has important performance implications.

#2about 4 minutes

Comparing the performance of for and foreach loops

While `for` loops were historically faster, optimizations in .NET 7 have made `foreach` performance nearly identical due to reduced enumerator overhead.

#3about 4 minutes

Why `Where().Count()` is faster than `Count(predicate)`

Using `Count()` with a predicate is significantly slower than chaining `Where()` and `Count()` because it results in a virtual method call instead of an instance method call.

#4about 4 minutes

When not to use `StringBuilder` for concatenation

`StringBuilder` is not always the fastest option for joining strings; for a small number of short strings, simple concatenation with `+` can be more performant due to `StringBuilder`'s resizing overhead.

#5about 3 minutes

The difference between `string.Empty` and an empty literal

Despite generating different IL code, `string.Empty` and the `""` literal compile to identical assembly instructions and have the same performance, with the only difference being compile-time usage constraints.

#6about 5 minutes

Safer null checking and the risk of operator overloading

Using the `==` operator for null checks is unsafe because it can be overloaded; the `is null` pattern should be used instead to avoid unexpected behavior.

#7about 4 minutes

How to terminate an application instantly

The `Environment.FailFast` method immediately terminates an application without executing `catch` or `finally` blocks, making it a drastic way to handle catastrophic failures.

#8about 4 minutes

Understanding the default banker's rounding in .NET

The `Math.Round` method in .NET uses banker's rounding by default, which rounds values ending in .5 to the nearest even integer, a behavior that can be surprising.

Related jobs
Jobs that call for the skills explored in this talk.
SabIna compys

SabIna compys
Vienna, Austria

Remote
20-100K
Intermediate
JavaScript
.NET
+1

Featured Partners

Related Articles

View all articles
CH
Chris Heilmann
Dev Digest 134 - Where pixels sing?
News and ArticlesWeAreDevelopers LIVE Data and Security Day is on Wednesday, 25/09/2024. Learn about OPC UA Updates, Best Practices for Using GitHub Secrets, Passwordless Web 1.5, Emerging AI Security Risks, Data Privacy in LLMs and get a chance to t...
Dev Digest 134 - Where pixels sing?
CH
Chris Heilmann
WeAreDevelopers LIVE days are changing - get ready to take part
Starting with this week's Web Dev Day edition of WeAreDevelopers LIVE Days, we changed the the way we run these online conferences. The main differences are:Shorter talks (half an hour tops)More interaction in Q&AA tips and tricks "Did you know" sect...
WeAreDevelopers LIVE days are changing - get ready to take part
CH
Chris Heilmann
Dev Digest 109 -Egg-citing things…
As we are heading into the Easter break, here are some things to spend some time on. There's resources on improving the performance of your code and you hear from the winners of CODE100 Amsterdam what it was like to be on stage. Also, hang tight as t...
Dev Digest 109 -Egg-citing things…
LM
Luis Minvielle
The Best Upcoming IT Webinars
Now that you already know what IT webinars are and how they can help you level up your professional appeal, you might want actually to get into one. Live tech webinars are one of the best ways to stay on top of the latest trends and tools because eit...
The Best Upcoming IT Webinars

From learning to earning

Jobs that call for the skills explored in this talk.