If you look at what’s new in C## 9, you’ll see records, init-only properties, and top-level statements get all the glory. And that’s fine, because they’re great. At the end of the bulleted list, I noticed support for local attributes on local functions.

When it comes to local functions, with C## 9 you can apply attributes to function declarations, parameters, and type parameters.

The most common use case I’ve seen is using the ConditionalAttribute. This attribute is used for checking conditional compilation symbols—instead of using #define DEBUG regions, for example, you can do it here. You can declare multiple attributes, just like for a “normal” method. For example:

#c# 9 #c# #function #attributes

Use local function attributes with C# 9
1.25 GEEK