dotnet / dotnet/vblang

Support System.Enum as generic type constraint.

Open
#306 34 comments 10 reactions 0 assignees View on GitHub
Approved-in-Principle LDM Considering
Dominant language
No language data
Stars
328
Forks
71
PR merge metrics
No merged PRs in 30d

Description

This concept has been discussed for years on the web and I just discovered that [C# 7.3](https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/generics/constraints-on-type-parameters#enum-constraints) now supports it:

```csharp
public static Dictionary EnumNamedValues() where T : System.Enum
{
var result = new Dictionary();
var values = Enum.GetValues(typeof(T));

foreach (int item in values)
result.Add(item, Enum.GetName(typeof(T), item));
return result;
}
```

@AnthonyDGreen would you happen to know what the discussion was for supporting this in VB as well when it was planned for C#?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.