Click here to Skip to main content
15,891,850 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to pass command line argument values to my main method in c# with VS2008
Posted

Right click on the project and select "Properties", navigate to the "Debug" tab and add your aragument values in the "Command line arguments:" box. Remember you may also need to select the "Working directory:".
 
Share this answer
 
Please search on google[^] (*) before posting any questions here.

(*) Could be called Topeka occasionally.
 
Share this answer
 
v2
Example to do this create a notepad file and save it with any name with a .cs extension and paste in the following code

C#
using System;
class Command
{

public static void Main(String[ ] args)
{
string name= args[0].ToString();
Console.WriteLine("Name Entered via Command Line argument is: "+name);
}
}


use the Visual Studio Command Prompt for this
Once this file is compiled(csc filename.cs) then after u run the exe then give ur name i.e

FileName Radix and then press enter and see the Magic

Command Line argument files can only run like this and if u try to run it in the development environment then it will prompt u an Exception saying
System.IndexOutOfRangeException

Do rate my answer once u find it useful

Thanks & Regards
Radix :rose:
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900