Introducing C# 9: Static anonymous functions

Introducing C# 9: Static anonymous functions

C# 9 brings an important improvement to anonymous functions by allowing the modifier static on them and we now have static anonymous functions ! Why Microsoft brought this feature ?

Introduction

C## 9 brings an important improvement to anonymous functions by allowing the modifier static on them and we now have static anonymous functions ! Why Microsoft brought this feature ? Because allocation matters ! Microsoft explains here that lambda are not cost less (https://devblogs.microsoft.com/premier-developer/dissecting-the-local-functions-in-c-7/) :

“Anonymous methods are not cheap:”

  • Overhead of a delegate invocation (very very small, but it does exist).
  • 2 heap allocations_ if a lambda captures local variable or argument of enclosing method (one for closure instance and another one for a delegate itself)._
  • 1 heap allocation_ if a lambda captures an enclosing instance state (just a delegate allocation)._
  • 0 heap allocations_ only if a lambda does not capture anything or captures a static state._

c# .net 5 c# 9 static anonymous function c++

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

jQuery Ajax CRUD in ASP.NET Core MVC with Modal Popup

In this article, we’ll discuss how to use jQuery Ajax for ASP.NET Core MVC CRUD Operations using Bootstrap Modal. With jQuery Ajax, we can make HTTP request to controller action methods without reloading the entire page, like a single page application.

Static in C# | What is static | Static Methods & Classes | C# Tutorial | Advanced C#

LIKE | COMMENT | SHARE | SUBSCRIBE In this tutorial, I will discussed about Static in C#. A static class is declared with the help of static keyword. A stati...

Static example in C# | What is static | Static Methods & Classes | Advanced C#

LIKE | COMMENT | SHARE | SUBSCRIBE In this tutorial, I will discussed about Static in C#. A static class is declared with the help of static keyword. A stati...

Anonymous Type in C# | Anonymous object | C# Bangla Tutorial | Advanced C#

LIKE | COMMENT | SHARE | SUBSCRIBE In this tutorial, I will discussed about Anonymous Type in C#. Blog : http://aspdotnetexplorer.blogspot.com Like our page ...

Anonymous array in C#| Anonymous Collection | C# Bangla Tutorial | Advanced C#

LIKE | COMMENT | SHARE | SUBSCRIBE In this tutorial, I will discussed about Anonymous Array in C#. Blog : http://aspdotnetexplorer.blogspot.com Like our page...