When implementing command line flags, should I prefix with a fowardslash (/) or hyphen (-)?

c#, command-line, command-line-arguments, console-application

Solution

You can (theoretically) use whatever you want, as the parameters are just strings passed to your command-line program.

Windows convention seems to prefer the use of the forward slash `ipconfig /all`, though there are programs that take a hyphen `gacutil -i` or even a sort-of environment variable syntax `setup SKUUPGRADE=1`.

*Nix convention seems to prefer the hyphen `-v` for single-letter parameters, and double hyphen `--verbose` for multi-letter parameters.

I tend to prefer hyphens, as they are more OS-agnostic (forward slashes are path delimiters in some OSes) and used in more modern Windows apps (nuget, for example).

Edit:

This would be a good place to recommend a library that does .NET command-line argument parsing: http://commandline.codeplex.com/

Problem

Are their any conventions (either written or just generally understood) for when to use a forward slash (/) or a hyphen (-) when reading arguments/flags from a command line? ``` C:\> myprogram.exe -a C:\> myprogram.exe /a ``` The two seem to be interchangeable in my experience, but I haven't used enough command line tools to say I've spotted any rules or patterns. Is there a good reason that either of them are used at all? Could I theoretically use an asterisk (*) if I wanted to?

Original source

Related problems