16 November
C# 11 – Improved method group
Programming
min. read

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.
Author
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.
SIMILAR POSTS
C# 11 – Everything you need to know
Programming
min. read
C# 11 – Numeric IntPtr
Programming
min. read
C# 11 – Pattern matching on Spans
Programming
min. read