Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,971 questions

51,913 answers

573 users

How to get command line arguments (args) in C#

3 Answers

0 votes
using System;

public class Program
{
	public static void Main(string[] args)
	{
         Console.WriteLine(string.Join(" ", args));
	}
}


// Set the arguments: 
// Project -> Properties... -> Debug -> Start Options -> Command line arguments: _____


/*
run:
  
-q arg zip 7z w xyz

*/


 



answered Jan 13, 2017 by avibootz
edited Feb 14, 2024 by avibootz
0 votes
using System;

public class Program
{
	public static void Main(string[] args)
	{
        string[] arr = Environment.GetCommandLineArgs();
 
        Console.WriteLine(string.Join(" ", arr));
	}
}


// Set the arguments: 
// Project -> Properties... -> Debug -> Start Options -> Command line arguments: _____


/*
run:
  
d:\...\ConsoleApplication_C_Sharp\bin\Debug\ConsoleApplication_C_Sharp.exe -q arg zip 7z w xyz

*/


 



answered Jan 13, 2017 by avibootz
edited Feb 15, 2024 by avibootz
0 votes
using System;

public class Program
{
	public static void Main(string[] args)
	{
        Console.WriteLine("Total Arguments: {0}", args.Length);
        
        foreach (var arg in args) {
            Console.WriteLine(arg);
        }
	}
}





/*
run:
  
Total Arguments: 3
aa
bb
cc
  
*/

 



answered Feb 14, 2024 by avibootz

Related questions

1 answer 240 views
1 answer 157 views
2 answers 234 views
1 answer 182 views
2 answers 183 views
183 views asked May 1, 2021 by avibootz
...