ToString() method deprecated on enums ???

1,182 views
Skip to first unread message

Jack

unread,
Jan 15, 2008, 9:00:17 AM1/15/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Hi,

Im using c# Visual studio 2005 .NET 2.0 and noticed that intellisense
says that the ToSting() method on my enum is deprecated (still works
though):

enum Music { Techno, Rap, Rock, Classical }
Music m1 = Music.Classical;
Console.WriteLine(m1.ToString());

If its deprecated, that what is the recommended way to do this?

Jack.


Andrew Badera

unread,
Jan 15, 2008, 10:33:33 AM1/15/08
to DotNetDe...@googlegroups.com
The deprecation message doesn't indicate the preferred alternative?

--ab



Cerebrus

unread,
Jan 15, 2008, 10:46:39 AM1/15/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
If you check the docs, you will see that the 2 overloads of the
Enum.ToString() method which require a IFormatProvider are obsolete.
The others are not. Intellisense atleast in this case, is misleading
you. ;-)

In your case therefore, you're not using deprecated code. Personally
though, I've always used Enum.GetName() instead.

Jack

unread,
Jan 15, 2008, 11:14:31 AM1/15/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Hi,

Do you mean like:
MessageBox.Show( Enum.GetName(m1.GetType(), m1)) ; ?

Also, I wasn't able to find any info on the deprecated functions on
the enum. - both in my docs and microsoft class library on-line. Can
you give me the url of where these deprecated functions are documented
(or discussed). Intellisense just has the [deprecated] text with no
reference to which of the overloaded ToString() functions are
deprecated.

Thanks.
> > Jack.- Hide quoted text -
>
> - Show quoted text -

Jack

unread,
Jan 15, 2008, 11:16:09 AM1/15/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Andy,

There was no notification or the like as to the preferred method to
use. Also, I wasn't able to find any info on the deprecated functions
on the enum. - both in my docs and microsoft class library on-line.
Any ideas where i can get it? Intellisense just has the [deprecated]
text with no reference to which of the overloaded ToString() functions
are deprecated.

Jack.

On Jan 16, 12:33 am, "Andrew Badera" <and...@badera.us> wrote:
> The deprecation message doesn't indicate the preferred alternative?
>
> --ab
>
> On 1/15/08, Jack <bradnerd...@hotmail.com> wrote:
>
>
>
>
>
>
>
> > Hi,
>
> > Im using c# Visual studio 2005 .NET 2.0 and noticed that intellisense
> > says that the ToSting() method on my enum is deprecated (still works
> > though):
>
> >             enum Music { Techno, Rap, Rock, Classical }
> >             Music m1 = Music.Classical;
> >             Console.WriteLine(m1.ToString());
>
> > If its deprecated, that what is the recommended way to do this?
>
> > Jack.
>
> --
> --Andy Baderahttp://andrew.badera.us/
> and...@badera.us
> (518) 641-1280- Hide quoted text -

Cerebrus

unread,
Jan 16, 2008, 11:20:55 AM1/16/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Yes, I think your example is correct. I did mean using GetName in a
similar way.

Here's the link to the docs page :
http://msdn2.microsoft.com/en-us/library/system.enum.tostring.aspx

On Jan 15, 9:14 pm, Jack <bradnerd...@hotmail.com> wrote:
> Hi,
>

Andrew Badera

unread,
Jan 16, 2008, 11:25:18 AM1/16/08
to DotNetDe...@googlegroups.com
Wow, that's pretty poor on Microsoft's part then. Anything I've encountered that is basic framework, deprecated by MS, has this info, like System.Net stuff from 1.1 --> 2.0.

--ab



On 1/15/08, Jack <bradn...@hotmail.com> wrote:

Andy,

There was no notification or the like as to the preferred method to
use. Also, I wasn't able to find any info on the deprecated functions
on the enum. - both in my docs and microsoft class library on-line.
Any ideas where i can get it? Intellisense just has the [deprecated]
text with no reference to which of the overloaded ToString() functions
are deprecated.

Jack.

On Jan 16, 12:33am, "Andrew Badera" < and...@badera.us> wrote:
> The deprecation message doesn't indicate the preferred alternative?
>
> --ab
>
> On 1/15/08, Jack < bradnerd...@hotmail.com> wrote:
>
>
>
>
>
>
>
> > Hi,
>
> > Im using c# Visual studio 2005 .NET 2.0 and noticed that intellisense
> > says that the ToSting() method on my enum is deprecated (still works
> > though):
>
> > enum Music { Techno, Rap, Rock, Classical }
> > Music m1 = Music.Classical;
> > Console.WriteLine(m1.ToString());
>
> > If its deprecated, that what is the recommended way to do this?
>
> > Jack.
>
> --
> --Andy Baderahttp://andrew.badera.us/
> and...@badera.us
> (518) 641-1280- Hide quoted text -
>
> - Show quoted text -


Reply all
Reply to author
Forward
0 new messages