dev-resources.site
for different kinds of informations.
Static Lambda in C# 12 : Performance Improvement
Published at
1/7/2025
Categories
webdev
csharp
dotnet
programming
Author
devesh_omar_b599bc4be3ee7
Author
25 person written this
devesh_omar_b599bc4be3ee7
open
A Static lambda, introduced in C# 12, is a lambda expression that cannot capture any variables from its enclosing scope. This means no closure class is generated, resulting in less memory allocation and potentially better performance.
Let’s work with some examples.
1. Sorting Collections:
Sorting a list of integers using a static lambda ensures no closures are created, reducing overhead during sorting
var numbers = new List<int> { 53, 31, 8, 1, 2,100,34,55,11,1 };
numbers.Sort(static (a, b) => a.CompareTo(b));
foreach (var item in numbers)
{
Console.WriteLine(item);
}
Console.ReadKey();
Result
2. Array Filtering
Filtering an array with a static lambda avoids capturing variables, making the filtering operation more efficient.
Console.WriteLine("--------Array Filtering-----------");
var array = new[] { 1, 2, 3, 4, 5 };
var filtered = Array.FindAll(array, static n => n > 3);
foreach (var item in filtered)
{
Console.WriteLine(item);
}
csharp Article's
30 articles in total
Dynamically Extracting Endpoint Names and Attributes from a Custom C# MVC API
read article
Integrating Azure OpenAI with .NET Applications Using Microsoft.Extensions.AI
read article
What is Quartz.Net and its simple implementation
read article
Beyond the Random Class: Cryptographic Randomness in .NET 6+
read article
I am a beginner in Python programming and I want to develop my skills.
read article
Demystifying AIContents in Microsoft.Extensions.AI
read article
Inter-process Communication with WitCom
read article
Mediator Pattern
read article
[WPF] Draw Tree Topology
read article
Game Dev Digest — Issue #264 - Game Dev Insights: AI Tools, VFX, Optimization & Tutorials
read article
Semantic Kernel: Crea un API para Generación de Texto con Ollama y Aspire
read article
Building Modern Desktop Applications with .NET 9: Features and Best Practices
read article
Orden en el Código .NET
read article
Building a Solana Wallet Backend with .NET (Part 1)
read article
Top 10 Programming Languages to Learn in 2025 🖥️
read article
ИСТОРИЯ .NET
read article
dotnet терминал команды
read article
Cqrs
read article
Why You Should Learn C#/.NET in 2025
read article
Custom Middleware Extensions in .NET Core Web API
read article
Qt/C++ Senior Experts Provide Customized Software Development Services
read article
Static Lambda in C# 12 : Performance Improvement
currently reading
Builder Pattern in C#: Practical Implementation and Examples
read article
WitCom: Modernizing Client-Server Communication
read article
Permission-Based Authentication and Authorization in .NET, via Cookies
read article
Simplifying CRUD Operations Using Primary Constructors for Dependency Injection with Generic Interfaces
read article
Entendendo Service, Repository e Controller, PT. 1
read article
Take your skills to the next level with these top courses on a HUGE DISCOUNT!
read article
Como Resolver o Erro DbUpdateConcurrencyException no Entity Framework
read article
Loops vs Recursividade
read article
Featured ones: