C#enum int不是int

时间:2017-08-20 10:45:22

标签: c# enums integer

这一行:

enum commandLine : int

应将以下枚举定义为int但不是,但不是。 这有什么不对?

using System;

enum commandLine : int
{
    DRIVELETTER = 0,
    URL
}
namespace not_int
{
    class Program
    {
        static void Main(string[] args)
        {
            String driveLetter;

            driveLetter = args[commandLine.DRIVELETTER]; //  Cannot implicitly convert type 'commandLine' to 'int' ... Yes You Can!
            driveLetter = args[(int)commandLine.DRIVELETTER]; // This works but feels like talking to a grown-up like he was a child:
            // You see, here we have an integer but to you it looks like an integer of a different type. Here I tell you it's an integer of the type you want, like your candies ...
            // This way you are happy like with your friday candy ...
        }
    }
}

0 个答案:

没有答案
相关问题