BUG: You receive a "CS0030" compilation error code while explicitly converting enum type to char type (814902)



The information in this article applies to:

  • Microsoft Visual C# .NET (2002)

SYMPTOMS

If you explicitly convert enum type to char type, you may receive the following compilation error message (CS0030):
Cannot convert type '<Your enum type>' to 'char'

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

WORKAROUND

To work around this problem, first explicitly convert enum type to int, and then explicitly convert int type to char type. You can do this with the following code:
char   ch = (char) (int) TestEnum.Val;

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Click Start, point to All Programs, point to Microsoft Visual Studio .NET, point to Visual Studio .NET Tools, and then click Visual Studio .NET Command Prompt. This automatically sets the environment to use Visual Studio .NET.
  2. Paste the following code in Notepad, or another text editor:
    using System;
    namespace TestApplication
    {
        enum TestEnum
        {
            Val 
        };
        class Class1
        {
            [STAThread]
            static void Main(string[] args)
            {
                char   ch = (char) TestEnum.Val;
            }
        }
    }
    
  3. Save the file as TestApplication.cs.
  4. At the command prompt, type the following command to compile the code.
    csc TestApplication.cs
You may receive the compilation error message that is described in the "Symptoms" section of this article.
Content Maintenance:3155

Modification Type:MajorLast Reviewed:1/16/2006
Keywords:kbCompiler kbProgramming kbbug KB814902 kbAudDeveloper kbAudITPRO