No need for a book. The internet is your best resource. This is a good introduction to the language: http://www.csharp-station.com/tutorial.aspx
There's not much special for command line applications. Arguments passed on the command line (seperated by spaces) get put into the args argument of main(string[] args). You can figure out how many arguments by calling args.Length. Loop over them like:
Code:
for(int i = 0; i < args.Length; i++)
{
Console.WriteLine(args[i]); //Print the args to output... or whatever you want to do with them
}
You can read from the console like:
Code:
string someData = Console.ReadLine(); //User enters information until they push enter, in which case the string gets stored in the newly-declared someData variable.
You can write to the console like:
Code:
Console.Write("Blah"); //Write blah to the console, without a new line
Console.WriteLine("Blah"); //Write blah to the console, then add a new line
Console.WriteLine("{0} is {1}", "programming", "fun"); //Write "programming is fun" to the console, then add a new line
File IO can be done (for many files) most efficiently like (make sure you have the System.IO using directive):
Code:
string pathToYourFile = @"C:\mydata.txt";
string[] fileLines = File.ReadAllLines(pathToYourFile);
//Then you can loop over the lines of your file
You can write messages to standard error (instead of standard output) like:
Code:
Console.Error.WriteLine("Error: You didn't get me any arguments!");
You can have your application exit with an error code:
Code:
Environment.Exit(-1);
Commonly:
Code:
//Check right number of arguments passed
if( args.Length != 2 )
{
Console.Error.WriteLine("Error: Wrong number of arguments");
Console.Error.WriteLine("Usage: Program.exe [First arg description] [Second arg description]");
Environment.Exit(-1);
}
Anyway, hopefully that main link and some of these idioms will help you.