16 November

C# 11 – Improved method group

min. read

Reading Time: < 1 minute
C# 11
C# 11

Let’s list all the features that C# 11 brings to the table. Let’s discuss them all one by one, with their use cases, and see how they can come in handy. At the bottom of each article, you can find a link to all 14 new C# features!

Improved method group conversion to delegate

In C# 10 and before, for some bizarre reason, the code behind method groups was not converted to the same IL code as lambdas or anonymous delegates. The code behind method groups was slower, and not memory efficient.

static readonly List<int> Numbers = Enumberable.Range(0, 100).ToList();

public int Sum()
    return Numbers.Where(x => Filter(x)).Sum(); // <- faster

public int SumMethodGroup()
    return Numbers.Where(Filter).Sum(); // <- slower

static bool Filter(int number)
    return number > 50;

In C# 11, this was fixed and now both versions would be memory and CPU efficient as they should be!

Further reading at dotnet GitHub page.

Current article:
Improved method group


Tomasz Juszczak


Technical Lead

Tomasz Juszczak

About prog

Founded in 2016 in Warsaw, Poland. Prographers mission is to help the world put the sofware to work in new ways, through the delivery of custom tailored 3D and web applications to match the needs of the customers.

Let's talk