質問

I want to pass two parameters to the following code, by giving numbers not from command line in debug

For example I want pass 4 4 to the code using entered values from user not fixed in command line to the :

class Program
{
    static void Main(string[] args  )
    {
        if (args.Length > 0)
            new Program(int.Parse(args[0] ));

        Console.ReadLine();
        Console.ReadLine();
        Console.Read();
        Console.ReadKey();
    }
}
役に立ちましたか?

解決

To get user input in "arg" format, you use Console.ReadLine():

string[] userArgs = Console.ReadLine().Split(' ');

The Console.ReadLine gets the entire input string, then to get the array we call .Split(). I split on spaces just like standard command line. Other delimiters are also possible, just pass in a different character to the Split function.

Of course, you could stick to using normal command line args and have the user enter them as part of the program call (not normally done on Windows since few people use command prompt, but it would work).

MSDN for Split in case you are interested!

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top