Dissecting local functions in C#.

by Nov 7, 2023

Dissecting local functions in C#.

At first glance, seemed like a complication, an ugly addition to the clean and elegant C# landscape! I didn’t get it.

Then, boom – I fell for these misfits.

I began to understand their charm.

Inserting the lower-level details into separate methods to make the intent of the code clear – that’s how it usually works, right? It’s a good strategy, but can lead to a clutter of tiny methods making the code difficult to decipher. Here lies the gray area, a fine balance to master.

Ever had code too specific and small for a separate method, yet you had to isolate it?

Enter local functions, your savior!

They simplify your code and transport the specifics into a function nestled at the end of your method. Out of sight, but not out of mind – just under the rug.

Do you find this compelling? Share your experiences with local functions in C#.

#

Subscribe to
The Daily Friction

A daily newsletter on automation and eliminating friction

Related Content

Improve Email Marketing with CRM integration 🚀

Improve Email Marketing with CRM integration 🚀 Notice your sales and marketing gears 🔩 straining? A simple fix might be at hand. Link your CRM to your email marketing platform for smoother operations. We've accomplished this by integrating Dynamics 365 with Spotler...

read more

An efficient government sounds great until it isn’t.

An efficient government sounds great until it isn't. I lived in the Netherlands most of my live. It has one of the most efficient governments in the world. Everything is digital and connected. But is it also one of the best countries related to freedom? I used to...

read more

Get ready to simplify your collections empty check in C#!

Get ready to simplify your collections empty check in C#! Ever noticed how different collection types in C#, like Array, List, or IEnumerable, have different methods to check if they're empty? Some ways are faster, some are slower... it's a bit of a maze. Well, here's...

read more
Share This