Hello ,
I have 2 questions about enums:
1) How can I recognize defined enum in other projects ,do I have to add
the full namespace path before it such as:
Projects.New Project.Test.MessageType (MessageType is an enum) - each
time I use it or I can somehow do it with using in the head of the file?
2) How can I validate if I got a valid enum value? Is it possible this
way:
if (System.Enum.IsDefined(typeof(MessageType), msgType) == false)
Is it ok?
Thank u!
Jon Skeet [C# MVP] - 02 Mar 2008 13:50 GMT
> 1) How can I recognize defined enum in other projects ,do I have to add
> the full namespace path before it such as:
>
> Projects.New Project.Test.MessageType (MessageType is an enum) - each
> time I use it or I can somehow do it with using in the head of the file?
Do it with a using directive just as you would for any other type.
> 2) How can I validate if I got a valid enum value? Is it possible this
> way:
>
> if (System.Enum.IsDefined(typeof(MessageType), msgType) == false)
>
> Is it ok?
Exactly - although I'd write it as:
if (!Enum.IsDefined(typeof(MessageType, msgType))
(i.e. have a using directive for the System namespace, and use ! to
negate the result of IsDefined instead of comparing with false.)

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Alfred Myers - 02 Mar 2008 14:23 GMT
Hi,
1) An enum is a type just as others and for that matter you can declare its
namespace in other classes as you do with other types. So declaring
using Projects.New Project.Test;
will enable you to use MessageType without having to specify the fully
qualified name.
2) Yes.
HTH
> Hello ,
> I have 2 questions about enums:
[quoted text clipped - 14 lines]
>
> *** Sent via Developersdex http://www.developersdex.com ***