Hi so I am trying to get the two values after user input --dimensions.
For example when I do: dotnet app.dll --dimensions 1 2 (In command line)
It prints
1
2
Which is the result I'm after.
But when I do: dotnet app.dll --test --dimensions 1 2
It returns hi, meaning that --test worked. But returns an error for --dimensions
hi
Unhandled exception. System.FormatException: Input string was not in a correct format.
   at System.Number.ThrowOverflowOrFormatException(ParsingStatus status, TypeCode type)
   at System.String.System.IConvertible.ToInt32(IFormatProvider provider)
   at System.Convert.ToInt32(Object value)
   at MainClass.Main(String[] args)
I don't want the argument to only work if its the first argument given. That is why I added --test before --dimensions
I want it to work when the argument --dimensions is placed anywhere.
For example dotnet app.dll --test --test --dimensions 1 2 --test
Which should return
hi
hi
1
2
hi
Im new with this as well :( Sorry.
Code:
using System;
class MainClass
{
    private static int value1, value2;
    static void Main(string[] args)
    {
        foreach (string value in args)
        {
            int for_dimensions = 0;
            string testing = "--test";
            if (value == "--dimensions" && args.Length >= for_dimensions + 2)
            {
                object test1 = args.GetValue(for_dimensions+1);
                value1 = Convert.ToInt32(test1);
                    
                object test2 = args.GetValue(for_dimensions + 2);
                value2 = Convert.ToInt32(test2);
                Console.WriteLine(value1);
                Console.WriteLine(value2);
            }
            if (value == testing)
            {
                Console.WriteLine("hi");
            }
            
        }
        
    }
}
Thank you
 
    