🪟 Windows TippsThe Gemini desktop app is now available for Windows(11.09.2026 um 17:06 Uhr)
🪟 Windows TippsAnytype Announces Next-Generation Anytwo Platform(11.09.2026 um 21:27 Uhr)
⚠️ Malware / Trojaner / VirenWindows 11 just dropped the tool ransomware abused, Microsoft says don’t restore WMIC(10.09.2026 um 20:11 Uhr)
⚠️ Malware / Trojaner / VirenVorsicht: Android-Malware verschlüsselt Ihre Handys und nimmt heimlich Fotos auf(11.09.2026 um 09:35 Uhr)
🕵️ SicherheitslückenMicrosoft geht endlich eines der nervigsten Probleme von Windows 11 an(11.09.2026 um 11:58 Uhr)
💾 IT Security ToolsSysinternals Suite(11.09.2026 um 12:00 Uhr)
🪟 Windows TippsThe Gemini desktop app is now available for Windows(11.09.2026 um 17:06 Uhr)
🪟 Windows TippsAnytype Announces Next-Generation Anytwo Platform(11.09.2026 um 21:27 Uhr)
⚠️ Malware / Trojaner / VirenWindows 11 just dropped the tool ransomware abused, Microsoft says don’t restore WMIC(10.09.2026 um 20:11 Uhr)
⚠️ Malware / Trojaner / VirenVorsicht: Android-Malware verschlüsselt Ihre Handys und nimmt heimlich Fotos auf(11.09.2026 um 09:35 Uhr)
🕵️ SicherheitslückenMicrosoft geht endlich eines der nervigsten Probleme von Windows 11 an(11.09.2026 um 11:58 Uhr)
💾 IT Security ToolsSysinternals Suite(11.09.2026 um 12:00 Uhr)

🔧 Programmierung 🕛 vor 1 Jahr 4 Min Lesezeit
0

Using Lambda Expressions Doesn't Make Your C# Code Functional

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht
📺
dev.to

I originally posted this post on .



Here are some other lessons I learned from that talk.






Here are two misconceptions about Functional Programming



1. "It's difficult"



When we hear "Functional Programming" what comes to mind is obscure jargon like monad, monoids, and endofunctors. They sound like you have to grow a beard to understand them. That scares programmers away from Functional Programming.



2. "I'm already using lambda expressions"



Lambda expressions and other recent features are syntactic sugar to make C# less verbose. Lambda expressions simplify delegates. And we've had delegates since C# 1.0 when C# looked way less functional than today.



The truth is functional programming could be simpler and lambda expressions don't make C# functional.






If lambda expressions and other features don't make C# functional, what is it then?



Expressions and Immutability.



Expressions mean everything has a result. Think of old-style switch/case statements vs switch expressions. We can assign the result of a switch expression to a variable, but not an old-style switch/case. If it can be assigned to the left of =, it's an expression.




CODE
// This is not an expression 😕🫸
switch (cardBrand)
{
case "Visa":
cardType = CardType.Visa;
break;

case "Mastercard":
cardType = CardType.MasterCard;
break;

default:
cardType = CardType.Unknown;
break;
}

// This is an expression 😀👉
var cardType = cardBrand switch
{
"Visa" => CardType.Visa,
"MasterCard" => CardType.MasterCard,
_ => CardType.Unknown
};






And immutability means that everything is set for life. Think of records, the init keyword, and private setters.



With these two concepts, to make C# functional, we should forget about classes and inheritance to go with static methods. We should forget constructor injection and go with regular method parameters. And we should separate data from behavior instead of keeping them side by side in a class that mutates state.



Following these two concepts, a dummy Calculator that looks like this




CODE
public class Calculator(ILogger _logger)
{
private int Value { get; private set; }
public void Add(int a)
{
_logger.Log($"Adding {a}");
Value += a;
}
}






will look like this instead




CODE
public static class FunctionalishCalculator
{
public int Add(Action<string> logger, int value, int a)
{
logger($"Adding {a}");
return value + a;
}
}






And in F#, it will look like this




CODE
let add logger value a =
logger $"Adding {a}"
value + a






A few lines of code. In F#, functions don't have to live in classes. The compiler infers parameters types. And we don't need to use the return keyword.






The perfect example of expressions and immutability in practice is LINQ.



LINQ is functional.



Every LINQ method returns a new collection. We don't have "void" LINQ methods. Expressions. And no LINQ methods change the input collection. Immutability.



That's why LINQ is the best of all C# features—It's functional.



Voilà! We don't need fancy features like . And go with expressions and immutability.






Refactor your coding career with my free 7-day email course. In just 7 emails, you'll get 10+ years of career lessons to avoid costly career mistakes.

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
The Gemini desktop app is now available for Windows
1 Quelle
Anytype Announces Next-Generation Anytwo Platform
1 Quelle
Windows 11 just dropped the tool ransomware abused, Microsoft says don’t restore WMIC
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Using Lambda Expressions Doesn't Make Your C# Code Functional

Thematisch verwandte Begriffe: Using, Lambda, Expressions, Doesnt · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...