Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enum.ToString() deprecated?

When I type .ToString() on an Enum type in Visual Studio, the Intellisense shows a "strike-through" line through ToString() (although it builds and works fine). It seems to indicate that Enum.ToString() is deprecated in some way. Is this true? If so, why?

alt text

like image 825
JoelFan Avatar asked Oct 04 '10 22:10

JoelFan


People also ask

What happens if you ToString an enum?

ToString() Converts the value of this instance to its equivalent string representation.

What is enum ToString?

C# Enum ToString() Method The ToString() method converts the value of this instance to its equivalent string representation. Firstly, set an enum. enum Vehicle { Car, Bus, Truck, Motobike }; To convert it to an equivalent string representation, use ToString().

Can we convert enum to string in C#?

We can convert an enum to string by calling the ToString() method of an Enum.


1 Answers

The Enum.ToString overloads that take an IFormatProvider, ToString(IFormatProvider) and ToString(String, IFormatProvider), are both obsolete, because the IFormatProvider isn't used anyway.

The other overloads, ToString() and ToString(String), are not obsolete.

It's a feature of ReSharper to strike out obsolete class members. It's apparently not very good at it.

like image 130
dtb Avatar answered Oct 07 '22 08:10

dtb