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