I'm improving my C# skills this last time by learning difficult stuff I found on the internet like TDD, Design Pattern, DDD and others... I discovered this exercise in an a book a friend of mine gave me, and I'm busy trying to to solve it.
So far below is my code but I'm not sure if I'm doing it right. Can you please assist?
public class myValidateArgument
{
public int Validate(string[] args)
{
if(int.TryParse(args, out value))
{
// int value
}
else
{
//
}
}
}
Exercise to solve
Write a ValidateArguments class with a Validate( string[] args ), returning an int.
Make sure that it does not throw any exceptions! Arguments are passed through the Validate method, and each one of them is optional.
Example arguments:
string[] args = {"--name", "SOME_NAME", "--count", "10"};
Arguments are case−insensitive, for example --name and --NAME should have the same effect.
Values that can be returned by Validate are:
−1 − user passed invalid data/arguments;
0 − everything is ok;
1 − user asked to print help information;
The user can pass the following three parameters:
count − an integer between 10 and 100 (inclusive);
name − a string of length between 3 and 10 characters;
help − user asked to print help information.
Although the help argument has a higher precedence, if other parameters are passed along with it, they must still be validated. If the parameters are valid, the function should return 1.
If an unrecognized argument or an empty array is passed, the function should return -1.
Example use case in the code:
var val = new ValidateArguments();
var result = val.Validate(args);