Skip to content

Support System.Enum as generic type constraint. #306

Open
@ericmutta

Description

@ericmutta

This concept has been discussed for years on the web and I just discovered that C# 7.3 now supports it:

public static Dictionary<int, string> EnumNamedValues<T>() where T : System.Enum
{
    var result = new Dictionary<int, string>();
    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#?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions