473,385 Members | 1,796 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

[deprecated] string Enum.ToString

Intellisense tells me in creating the first MessageBox below that string
Enum.ToString is deprecated. Is the preferred method shown in the second
MessageBox below? What is the preferred method to convert enum to string?

private void button3_Click(object sender, EventArgs e)
{
DriveInfo d = new DriveInfo("C");

MessageBox.Show(d.DriveType.ToString());
MessageBox.Show("" + d.DriveType);
}

-Tim Sprout
Jul 12 '07 #1
2 5323
Tim Sprout wrote:
Intellisense tells me in creating the first MessageBox below that string
Enum.ToString is deprecated. Is the preferred method shown in the second
MessageBox below? What is the preferred method to convert enum to string?

private void button3_Click(object sender, EventArgs e)
{
DriveInfo d = new DriveInfo("C");

MessageBox.Show(d.DriveType.ToString());
MessageBox.Show("" + d.DriveType);
}
Intellisense is a little misleading on that. The overload of ToString
that takes in an IFormatProvider, either as the only parameter or as the
second parameter, is now obsolete and you should use one of the
overloads that does not take an IFormatProvider. When you first start
to type ToString the overload that is shown is the one that takes only
an IFormatProvider parameter which causes the deprecated to appear since
that overload has the Obsolete attribute on it. As long as you are
using either ToString() or ToString(string) then you are OK.
--
Tom Porterfield
Jul 12 '07 #2
Tim Sprout wrote:
>Intellisense tells me in creating the first MessageBox below that string
Enum.ToString is deprecated. Is the preferred method shown in the second
MessageBox below? What is the preferred method to convert enum to string?

private void button3_Click(object sender, EventArgs e)
{
DriveInfo d = new DriveInfo("C");

MessageBox.Show(d.DriveType.ToString());
MessageBox.Show("" + d.DriveType);
}

"Tom Porterfield" wrote:

Intellisense is a little misleading on that. The overload of ToString
that takes in an IFormatProvider, either as the only parameter or as the
second parameter, is now obsolete and you should use one of the overloads
that does not take an IFormatProvider. When you first start to type
ToString the overload that is shown is the one that takes only an
IFormatProvider parameter which causes the deprecated to appear since that
overload has the Obsolete attribute on it. As long as you are using
either ToString() or ToString(string) then you are OK.
--
Tom Porterfield

Ah! Thanks much, Tom.

-Tim Sprout
Jul 13 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Anonieko Ramos | last post by:
Answer: http://weblogs.asp.net/tims/archive/2004/04/02/106310.aspx by Tim Sneath I've come across the situation on a number of occasions when coding where I've wanted to convert from a string...
7
by: Henke | last post by:
Hi! Has anyone a nice way to connect a enum to a string value. Now I declare a const string in the same class as my enum is defined. But I doubt that's the "object oriented" way of doing it. Any...
6
by: Sanjay Pais | last post by:
Is there anyway I can define an enum to have a value of a string or character type? for example I would like to have public enum HOW_GOOD { AWESOME = "A", GREAT= "G",
3
by: Sanjay Pais | last post by:
I know that string/char enum is not possible in c# (.NET2.0) I need to create the equivalent of this: public enum HOW_GOOD { AWESOME = "A", GREAT= "G", NOT_TOO_BAD = "N", TERRIBLE="T" }
9
by: rsine | last post by:
I have developed a program that sends a command through the serial port to our business system and then reads from the buffer looking for a number. Everything worked great on my WinXP system, but...
5
by: Barry | last post by:
Hello, In VS2003, I tried using an enum and setting it into a field in a datarow. It seems as if the datatype of the field in the row determined what went into the field. If the datatype was...
15
by: Fariba | last post by:
Hello , I am trying to call a mthod with the following signature: AddRole(string Group_Nam, string Description, int permissionmask); Accroding to msdn ,you can mask the permissions using...
8
by: tony | last post by:
Hello! I have below a for loop and a switch in the for loop. I have also a enum called colBlowStep with some values. I have also an array called m_columnBlowStep with some strings. All items in...
6
by: Rico | last post by:
Hello, I'm looking for a way to reference the string name of an enumerator. I know in VB.net you can do "MyEnum.ToString" and get the name instead of the integer value. Is there a way I can do...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.