Skip to content

Method group natural type improvements C# 13.0readabilitycorrectness

Method groups are now more likely to identify the correct method.

Method groups are a group of methods with the same name on a type but with different parameters (overloads).

Prior to C# 13 the type resolution was quite basic and you often needed to cast the method group in order to get the correct method.

C# 13 improves this by pruning inapplicable overloads earlier so the compiler is more likely to identify the correct method without additional casts.

Code

C#
// The compiler can now determine the correct overload
Task.Run(LocalFunction);

void LocalFunction() { }
C#
// Ambiguous between Action and Func<Task> overloads
// Required an explicit cast to resolve
Task.Run((Action)LocalFunction);

void LocalFunction() { }

More information