K
Ken Allen
The ToString() function, when applied to a variable that is an enumeration
type, results in a string that is the name of the enumerated value that was
defined in the source code. This is cool, but how does one override the
function to have some values return a different string?
For example, suppose I have an enum with value for the types of DVD media
like
public enum DVD_Media
{
DVD_ROM = 1,
DVD_R,
DVD_RW,
DVD_R_Plus,
DVD_RW_Plus,
DVD_RAM
}
but I want the values to print as "DVD-ROM", "DVD-R", "DVD-RW", "DVD+R",
"DVD+RW", and "DVD-RAM" -- the C# syntax does not seem to permit me a
mechanism to override the ToString() method on this specific enumeration.
-Ken
type, results in a string that is the name of the enumerated value that was
defined in the source code. This is cool, but how does one override the
function to have some values return a different string?
For example, suppose I have an enum with value for the types of DVD media
like
public enum DVD_Media
{
DVD_ROM = 1,
DVD_R,
DVD_RW,
DVD_R_Plus,
DVD_RW_Plus,
DVD_RAM
}
but I want the values to print as "DVD-ROM", "DVD-R", "DVD-RW", "DVD+R",
"DVD+RW", and "DVD-RAM" -- the C# syntax does not seem to permit me a
mechanism to override the ToString() method on this specific enumeration.
-Ken