Type of issue
Other (describe below)
Description
The code example under the "Enum Constrains" defines a static extension method:
extension<T>(T) where T : System.Enum
{
public static Dictionary<int, string> EnumNamedValues() { ... }
}
It then goes on to show an example of using that extension method:
var map = EnumNamedValues<Rainbow>();
This line works within the specific example, but only because the source code has a using static declaration at the top. This declaration is not visible in the article. If someone were to copy the code from the article, and try to call the extension method in this fashion from outside of the class where it was declared, and without an equivalent using static declaration, then it would fail to compile.
The example should be updated to show the extension method being called as an extension method:
var map = Rainbow.EnumNamedValues();
Page URL
https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/generics/constraints-on-type-parameters#enum-constraints
Content source URL
https://github.com/dotnet/docs/blob/main/docs/csharp/programming-guide/generics/constraints-on-type-parameters.md
Document Version Independent Id
22b2c77c-2721-9384-3863-046e391ea4b1
Platform Id
21c05da0-f244-f1c8-dad8-0fb2d0432eca
Article author
@BillWagner
Metadata
- ID: 5712215d-b167-d9cb-bd51-80df0e300d50
- PlatformId: 21c05da0-f244-f1c8-dad8-0fb2d0432eca
- Service: dotnet-csharp
- Sub-service: fundamentals
Related Issues
Associated WorkItem - 582354
Type of issue
Other (describe below)
Description
The code example under the "Enum Constrains" defines a static extension method:
It then goes on to show an example of using that extension method:
This line works within the specific example, but only because the source code has a
using staticdeclaration at the top. This declaration is not visible in the article. If someone were to copy the code from the article, and try to call the extension method in this fashion from outside of the class where it was declared, and without an equivalentusing staticdeclaration, then it would fail to compile.The example should be updated to show the extension method being called as an extension method:
Page URL
https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/generics/constraints-on-type-parameters#enum-constraints
Content source URL
https://github.com/dotnet/docs/blob/main/docs/csharp/programming-guide/generics/constraints-on-type-parameters.md
Document Version Independent Id
22b2c77c-2721-9384-3863-046e391ea4b1
Platform Id
21c05da0-f244-f1c8-dad8-0fb2d0432eca
Article author
@BillWagner
Metadata
Related Issues
Associated WorkItem - 582354