Re: Compiler Error CS0702

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



On Fri, 18 Apr 2008 13:06:05 -0700, PIEBALD <PIEBALD@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

So, if you are designing a _new_ language, to write software for some
_not-yet-existent_ platform, and it includes enums and generics, you would
_not_ allow enum as a constraint for a generic? Why? That's what I want to
know.

I'm not a language designer, so knowing what I would do is sort of pointless. I don't have the kind of knowledge and experience that would allow me to provide a reliable answer to that question. Unless you're an experienced language designer, I doubt you do either, for what it's worth.

Also, your question is too vague. It doesn't provide any other specifics about the language that might constrain this particular area of the design. In particular, the current state of C# appears to me to be a consequence of wanting to support both reference types and value types, along with wanting to support enums as value types. Change either of those design goals, and what's possible and/or desirable in generics changes as well.

Personally, I feel that both of those goals are important. Much more important than the goal of supporting a special class like System.Enum as a constraint in a generic. The utility of the former goals is as broad as the utility of the latter is not.

As for why one would not support System.Enum as a constraint for a generic given those stated goals, please read the message I already posted, as it already describes my thinking on the matter. There's no need to repeat myself.

Pete
.



Relevant Pages

  • Re: More Generics warnings.
    ... chance to ruminate about generics in the hopes of shedding some light ... is something we deal with regularly, eg., with List: a List reference ... The wildcard constraint can be reduced from "Object" to some more ... promoting assignments are valid: ...
    (comp.lang.java.programmer)
  • Re: Compiler Error CS0702
    ... So I see no reason for the spec to ... I have also pointed out that the specification does specifically disallow the use of System.Enum as a constraint, contrary to your statements that it doesn't. ... As is the case for any value type, assigning an instance of the value type to a reference type variable requires boxing. ... generics treat value type parameters differently from reference type parameters. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Generics with multiple constrains
    ... It seems that I can't use generics in my example, even though I want to, ... looking at this very narrowly in terms of generic constraint lists. ... C++ to VB Converter ... C++ to Java Converter ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: Generics in .NET 2.0 SUCK
    ... The reason Generics in .NET 2.0 SUCK? ... when you specify a type parameter without ... probably there is a way to specify a method constraint for T ... > My second thought was that there might be some interface like IArithmetic. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Generics with multiple constrains
    ... looking at this very narrowly in terms of generic constraint lists. ... David Anton ... C++ to VB Converter ... I guess generics may not be applied to my specific example. ...
    (microsoft.public.dotnet.languages.csharp)