• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

C# expanding skills: Command Line Options

thecoolnessrune

Diamond Member
Hey guys, I have rather rudimentary programming skills (fun hobby to me), and one of the things I was trying to do was have command line options in my program. Like how you can type bootsect.exe /NT60 H: to tell bootsect what to do.

I want to do something like that for a command line program I'm writing for ultrabasic cryptography. Basically all it does is take the program and then the command line arguments as a text file to open and then a number setting the cryptography key (anywhere from 1 to 100 or something like that).

Can anyone give a good description of how to get command line arguments in C#? I've simply never used them before and I can't seem to find any online resources that explain it in a way I can understand.

Thanks for shedding any light on this 🙂
 
So THATS why string[] args is always in the Main method of every program you start in VS 2005. My professor always told me "you wont be using this don't worry about it." Now I feel *stupid* that I didn't understand this before! /facepalm

Thanks Cogman. I appreciate that.
 
So THATS why string[] args is always in the Main method of every program you start in VS 2005. My professor always told me "you wont be using this don't worry about it." Now I feel *stupid* that I didn't understand this before! /facepalm

Thanks Cogman. I appreciate that.

Hahaha, you have to love some profs. It wouldn't have taken significantly more time to say "This is how arguments get passed in when running from the command line, but we'll skip over that for now."
 
Hahaha, you have to love some profs. It wouldn't have taken significantly more time to say "This is how arguments get passed in when running from the command line, but we'll skip over that for now."

🙂 Yep, I'm half convinced they don't really know what things like that does when it isn't in their lesson plans.
 
hmm, i figured there'd some wiz-bang .net way. not much different than argv/argc.

🙂 If it ain't broke, don't fix it.

If you REALLY want some wizbang way to get it, then there is the System.Environment.GetCommandLineArgs() method. However, since it is all setup in the application initialization, I don't really see the point of calling a separate function to get information that is available at the start of the program. It is almost like going the wrong way around to get constant values.
 
🙂 If it ain't broke, don't fix it.

If you REALLY want some wizbang way to get it, then there is the System.Environment.GetCommandLineArgs() method. However, since it is all setup in the application initialization, I don't really see the point of calling a separate function to get information that is available at the start of the program. It is almost like going the wrong way around to get constant values.

I've used that function a few times. It has its places. 🙂
 
Back
Top