the enum declaration below is simply a c# language construct.  but basically an enum 
is just a value type that has a bunch of static public fields, the real value of the 
each field is based on the underlying type (by default an int32).

so something like this should work:

public class MonetaryUnit : Enum
{
        static public readonly string USDollar = "American";
        static public readonly string AUDollar = "Australian";
        etc,
}

i don't really know if inheriting from Enum really even offers you anything, you 
should be able to use the static methods on Enum (but i am guest making the 
assumption, i have never done this).

but if what are after is the string, just create a class of static read only fields, 
then there is no reason to even use the .ToString() method.

-joe


-----Original Message-----
From: Clark, Michael (OFM) [mailto:[EMAIL PROTECTED]
Sent: Monday, June 23, 2003 12:56 PM
To: [EMAIL PROTECTED]
Subject: [ADVANCED-DOTNET] ToString Implementation in an Enum


There's gotta be a way, but I can't find it...

Suppose you have an enum, such as:

public enum MonetaryUnit
{
        USDollar,
        AUDollar,
        CDNDollar
}

And you would like the expression MonetaryUnit.USDollar.ToString() to return
something like "American", or AUDollar to return "Australian", etc.

How would you go about implementing this?

Reply via email to