471,306 Members | 1,242 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,306 software developers and data experts.

ToString() of an enum.

Hi

Since an enum member object has a ToString() method, i wonder if it can be
overriden .

johan

Jan 6 '06 #1
6 2149
Did you try?
If not why not?
If you did then why ask?

"Sagaert Johan" <RE*************@hotmail.com> wrote in message
news:uE**************@tk2msftngp13.phx.gbl...
Hi

Since an enum member object has a ToString() method, i wonder if it can be
overriden .

johan

Jan 6 '06 #2
Probably what Johan is asking in effect is that since System.Enum is an
abstract class it must be derived from, therefore how can I derive from it
so that I can override ToString? The answer is that you can't derive from
it. It's one of those classes which is treated specially by the C# language
(and I would guess by every other .NET language too), like System.Delegate.
Declaring an enum presumably causes the compiler to generate a derived
classs in much the same way that declaring a delegate does.

"Nick Hounsome" <nh***@nickhounsome.me.uk> wrote in message
news:VP*******************@fe1.news.blueyonder.co. uk...
Did you try?
If not why not?
If you did then why ask?

"Sagaert Johan" <RE*************@hotmail.com> wrote in message
news:uE**************@tk2msftngp13.phx.gbl...
Hi

Since an enum member object has a ToString() method, i wonder if it can
be
overriden .

johan


Jan 6 '06 #3
I was thinking more along the lines of the impossibility of adding a method
to an enum derived,override or whatever.

I've always thought that you should at least be able to add static stuff to
an enum - I can't see why not

"Clive Dixon" <cl*******************@digita.noluncheonmeat.com > wrote in
message news:OL**************@TK2MSFTNGP10.phx.gbl...
Probably what Johan is asking in effect is that since System.Enum is an
abstract class it must be derived from, therefore how can I derive from it
so that I can override ToString? The answer is that you can't derive from
it. It's one of those classes which is treated specially by the C#
language (and I would guess by every other .NET language too), like
System.Delegate. Declaring an enum presumably causes the compiler to
generate a derived classs in much the same way that declaring a delegate
does.

"Nick Hounsome" <nh***@nickhounsome.me.uk> wrote in message
news:VP*******************@fe1.news.blueyonder.co. uk...
Did you try?
If not why not?
If you did then why ask?

"Sagaert Johan" <RE*************@hotmail.com> wrote in message
news:uE**************@tk2msftngp13.phx.gbl...
Hi

Since an enum member object has a ToString() method, i wonder if it can
be
overriden .

johan



Jan 6 '06 #4
(This is my third attempt to post this - twice with Google, and now with MSDN.
Apologies if it shows up too many times.)

"Sagaert Johan" wrote:
Since an enum member object has a ToString() method, i wonder if it can be
overriden .


Unfortunately not. Enums are one of the least OO aspects of C#.
See http://msmvps.com/blogs/jon.skeet/ar...classenum.aspx for
my proposals to improve matters.

Jon

Jan 6 '06 #5
Sagaert Johan wrote:
Since an enum member object has a ToString() method, i wonder if it can be
overriden .


Unfortunately not. There are many aspects of enums which just aren't
object-oriented. See
http://msmvps.com/blogs/jon.skeet/ar...classenum.aspx for
what I'd like to see done about it :)

Jon

Jan 7 '06 #6
(I thought I'd replied to this before, but apparently I hadn't...)

Sagaert Johan wrote:
Since an enum member object has a ToString() method, i wonder if it can be
overriden .


Unfortunately not. Enums are possibly the least OO part of C#/.NET.

See http://msmvps.com/blogs/jon.skeet/ar...classenum.aspx
for my view on how things could be improved.

Jon

Jan 7 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Suresh | last post: by
3 posts views Thread by raffelm | last post: by
10 posts views Thread by Ken Allen | last post: by
4 posts views Thread by avivgur | last post: by
3 posts views Thread by Jon Shemitz | last post: by
1 post views Thread by Leif Eirik Olsen | last post: by
8 posts views Thread by John Cobb | last post: by
2 posts views Thread by Tim Sprout | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.