Console app arguments, how arguments are passed to Main method

前端 未结 10 1195
醉话见心
醉话见心 2020-12-08 09:30

This would be question from c# beginner. When I create console application I get Main method with parameter args as array string. I do not understand how t

10条回答
  •  情话喂你
    2020-12-08 10:26

    in visual studio you can also do like that to pass simply or avoiding from comandline argument

     static void Main(string[] args)
        {
            if (args == null)
            {
                Console.WriteLine("args is null"); // Check for null array
            }
            else
            {
                args=new string[2];
                args[0] = "welcome in";
                args[1] = "www.overflow.com";
                Console.Write("args length is ");
                Console.WriteLine(args.Length); // Write array length
                for (int i = 0; i < args.Length; i++) // Loop through array
                {
                    string argument = args[i];
                    Console.Write("args index ");
                    Console.Write(i); // Write index
                    Console.Write(" is [");
                    Console.Write(argument); // Write string
                    Console.WriteLine("]");
                }
            }
    

提交回复
热议问题