public static void Main()
Console.WriteLine("Hello World");
var args = "-v -n 2 r -c3".Split(" ");
var lib = new libgetopt(args) { Debug = true };
while ((arg = lib.GetOptions()) != -1)
static void L(string s) => Console.WriteLine(s);
public libgetopt(string[] args)
public bool Debug { get; set; }
public OptArg GetOptions()
if (args == null || args.Length == 0 || optIdx >= args.Length)
string opt = args[optIdx];
else if (opt.StartsWith("-"))
L($"Valid option (-{o})");
L($"Argument w/o whitespace ({arg})");
else if (args.Length > (optIdx + 1) && !args[optIdx + 1].StartsWith("-"))
L($"Argument w/ whitespace ({arg})");
L($"Invalid option ({opt}), skip");
private void L(string s) { if (Debug) Console.WriteLine($"[libgetopt] {s}"); }
public int Option { get; private set; }
public string Arguments { get; set; }
public OptArg(int option)
public static implicit operator OptArg(int option) => new OptArg(option);
public static implicit operator int(OptArg optArg) => optArg.Option;