Jon said:
Well, I meant allowing them to behave like proper objects - with
constructors, inheritance, defining their own methods etc. A restricted
set of values of (or derived from) a particular type, basically.
Pascal enums define a set of new ordinal values. They're not object
oriented, but they are more strongly typed than CLR enums. It's
reasonably common in Pascal to define an array indexed by an enum, which
is basically what the original poster is after:
type
MyEnum = (enFoo, enBar, enBaz);
MyArray = array[MyEnum] of string;
I believe the root of the relative deficiency in C# is similar to the
early warnings about use of 'const', and the lack of default arguments
in C#, because these things burn values into user expressions and
callsites, rather than leaving things late-bound.
I believe it's all part of the general orientation in C# towards not
breaking code by upgrading components (cf. odd overloading rules in C#
when interacting with inheritance, for example).
That gets rid of a fair amount then, really. What about Delphi?
The above is pretty much the same in Delphi, apart from scoped
enumerations in Delphi for .NET - one can use MyEnum.enFoo, or
preferably drop the conventional 'xx' enum value prefix altogether.
As a bonus, in Delphi for Win32, one can use {$SCOPEDENUMS ON} to enable
the same behaviour. I implemented it soon after joining CodeGear.
-- Barry