Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
My_Response
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { args = new string[] {"--NAME","2iom22nkjk2"}; var val = new ValidateArguments(); var result = val.Validate(args); Console.WriteLine(result); } } } public class ValidateArguments { private const int WRONG_ARGS = -1; private const int OK_ARGS = 0; private const int HELP_ARGS = 1; private const string NAME_ARG = "--NAME"; private const string COUNT_ARG = "--COUNT"; private const string HELP_ARG = "--HELP"; public int Validate(string[] args) { if (args == null) { return WRONG_ARGS; } if (!args.Any()) { return WRONG_ARGS; } var help_present = false; var args_valid = true; for (var i = 0; i < args.Length;) { var arg = args[i].ToUpperInvariant(); if (arg == NAME_ARG) { if (i + 1 >= args.Length) { args_valid = false; break; } // we do not care whats up next var val = args[i + 1]; if(val.Length < 3 || val.Length>10){ args_valid = false; break; } i += 2; } else if (arg == COUNT_ARG) { if (i + 1 >= args.Length) { args_valid = false; break; } var val = args[i + 1]; int count = -1; if (!int.TryParse(val, out count)) { args_valid = false; break; } if(count < 10 || count > 100){ args_valid = false; break; } i += 2; } else if (arg == HELP_ARG) { help_present = true; i += 1; } else { args_valid = false; break; } } if (args_valid) { if (help_present) { return HELP_ARGS; } return OK_ARGS; } return WRONG_ARGS; } }
run
|
edit
|
history
|
help
0
Reflection custom test
sdfrgyhjuiku7y6t5rf
2.2 gz
StringCompare
C# Abstract class and method
XPath
test
Md5 hash
Amortizacion de prestamos con el metodo Frances
haha