0

This line:

enum commandLine : int

should define following enums as int but no, it does not. What is wrong here?

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 ...
        }
    }
}
  • `commandLine : int` is redundant. `enum` inherits from `int` by default https://stackoverflow.com/questions/6348924/enum-inheriting-from-int – Guy Aug 20 '17 at 10:53
  • Want a `int` use a `int`, want a `enum` use a `enum`... – Kevin Smith Aug 20 '17 at 11:01
  • Have you tried wrapping up in your own classes? https://stackoverflow.com/questions/261663/can-we-define-implicit-conversions-of-enums-in-c ? – Kevin Smith Aug 20 '17 at 11:05
  • @Guy: I am perfectly aware that the default enum type is int but If I did not write that I'd be suggested to use it ... Being clear and sometimes overly clear in your questions help to sort out unnessesary answers and comments. –  Aug 20 '17 at 11:06
  • @Kevin Smith: I will do that from now on. –  Aug 20 '17 at 11:07

0 Answers0