Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

15
  • 79
    Yeah, very hardcore. I have the utmost respect for someone who can code in IL, and know how the features are supported at the higher language level - a level which many of us still see as being low level under applications, business rules, UI's, component libraries, etc. Commented Mar 25, 2012 at 1:31
  • 15
    What I'd really like to know is why the C# team hasn't started allowing this yet, since it is already supported by MSIL. Commented Sep 19, 2012 at 0:30
  • 30
    @MgSam - From Eric Lippert: There's no particularly unusual reason why not; we have lots of other things to do, limited budgets, and this one has never made it past the "wouldn't this be nice?" discussion in the language design team. Commented Sep 19, 2012 at 0:58
  • 6
    @LordofScripts: I think the reason is that that since a class which constrains a T to System.Enum wouldn't be able to do all the things with T that people might expect, the authors of C# figured they may as well forbid it altogether. I consider the decision unfortunate, since it C# had simply ignored any special handling of System.Enum constraints, it would have been possible to write a HasAnyFlags<T>(this T it, T other) extension method that was orders of magnitude faster than Enum.HasFlag(Enum) and which type-checked its arguments. Commented Apr 12, 2013 at 16:27
  • 4
    @MichaelBlackburn It's more complicated than it sounds, mostly due to bit flags on enums. A github user named HaloFour gives a good summary in this Roslyn issue. Commented Oct 26, 2015 at 21:22