The word miners in the NDepend blogging mines clue us in on an update to the C# language:
A few remarks:
- If the extension is generic, the type parameter (if any) is specified immediately after the
extensionkeyword.- The receiver
ReadOnlySpan<T> spanapplies to one or more extension methods (or members) declared within the sameextensionblock. This logical grouping is a core advantage of the new syntax, improving clarity and structure when extending a type.- As far as the C# compiler is concerned, the two methods
Truncate()are strictly equivalent. Therefore, one must be commented out for the program to compile.- Notice the call to
AsSpan()in the first line. Extension methods require the receiver type to match exactlyReadOnlySpan<T>, hence it doesn’t apply tostringunless you explicitly cast. This is not specific to the new syntax but worth mentioning.
Read on for examples of how extension methods and extension members will open up opportunities to improve existing C# code.