The thing about constraints is that the name is misleading - they were
actually added not constrain the user of a class but to remove constraints
on the implementor the class!
The point of a constraint is to allow access to methods and properties of an
object of parameterized type without casting but since Enum adds nothing to
Object (all the interesting methods are static) it isn't allowed.
This seems to be a common policy in C# - whatever seems unnecessary or
redundant is explicitly prohibited - and in many cases they have carried it
too far. Personally I think you should be allowed to write stuff like "where
T: object" if you want - what's the harm? And in the case of enums I agree
that there are cases where it would be useful.
"Rune B" <ye*******@bingo.com> wrote in message
news:ex**************@TK2MSFTNGP12.phx.gbl...
Hi Group.
I would like to do the following:
public static DecriptiveCollection GetValuesForDisplay<T>() where T :
System.Enum
{
DecriptiveCollection list = new DecriptiveCollection ();
foreach(T value in Enum.GetValues(typeof(T)))
{
// add description Attributes and enum values to collection
}
return list;
}
But I recieve an "Contstraint cannot be special class Enum" - compile
error ...
- why is this?
Regards, Rune