Hmmm ... bits of confusion going on in this thread ...
There is no problem whatsoever in passing an enum type as a paremeter and often it is a better choice than say a boolean flag. Take the RemotingConfiguration.RegisterWellknownServiceType static method. Here is the signature ...
RemotingConfiguration.RegisterWellknownServiceType( Type typeToRemote, string uri, WellKnownObjectMode mode);
its that last param which is the interesting one - WellKnownObjectMode is defined as follows:
enum WellKnownObjectMode
{
Singleton
SingleCall
}
so only two values. So why didn't they use a boolean as the last parameter? Because the code is much more explicit using an enum - from looking at the method call you cal see gthe activation mode of the remote objectwithout having to check the docs to see what true and false mean.
By defaults enums are stored as 32 bit integers but you can change this using "inheritance like" syntax
enum WellKnownObjectMode : byte
{
Singleton
SingleCall
}
The above says 8 bits is enough to store the value.
Regards
Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk
Peter said:
Hi,
I think that the underlying type is integer by default
Hm, I am not sure about this, but consider the following example. It's a
slightly different version of the previous one.
private enum MyEnum { ONE = 1, TWO = 2, THREE = 3 }
private void PrintMyEnum(MyEnum e)
{
switch (e)
{
case MyEnum.ONE:
Console.WriteLine("MyEnum: {0}", e);
break;
case MyEnum.TWO:
Console.WriteLine("MyEnum: {0}", e);
break;
case MyEnum.THREE:
Console.WriteLine("MyEnum: {0}", e);
break;
default:
break;
}
}
this.PrintMyEnum(MyEnum.ONE);
this.PrintMyEnum(MyEnum.TWO);
this.PrintMyEnum(MyEnum.THREE);
This one prints:
MyEnum: ONE
MyEnum: TWO
MyEnum: THREE
So, what's the type now?
Regards
Catherine