Having problems with this program building and am not getting errors

Posted 22 August 2011 - 08:56 PM

I'm teaching myself C#, since I want to build in XNA, I know some C++ (been going to school for it) but am stuck on why this programe isn't working, especially since I'm using code from an Adobe PDF book on learning C#. Iam not getting errors just the output is not showing what the program should do. Here is the code your help is appreciated so I can move onto my next lesson, thanks.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SwitchCase
{
class SwitchCaseExample
{
//Demonstrates the use of switch...case statement along with
//the use of command line argument
static void Main(string[] userInput)
{
int input = int.Parse(userInput[0]);
//convert the string input to integer
//will throw a runtime exception if there is no input at runtime or if
//the input is not castable to integer
switch (input) //what is input
{
case 1: //if it is 1
Console.WriteLine("You typed 1 (one) as the first command line argument");
break; //get out of the switch block
case 2: //if it is 2
Console.WriteLine("You typed 2 (two) as the first command line argument");
break; //get out of the switch block
case 3: //if it is 3
Console.WriteLine("You typed 3 (three) as the first command line argument");
break; //get out of the switch block
default: // if it is not any of the above
Console.WriteLine("You typeda number other than 1,2,3");
break; //get out of the switch block
}
}
}
}

Oh and how do I turn line numbers on is visual studio 2010 Ultimate using C#?

Re: Having problems with this program building and am not getting errors

Posted 22 August 2011 - 10:06 PM

sorry I'm still unsure what I need to do in this section can someone please help, thanks;)

why would I need to enter a # there? Sorry confused when I go to this section am I supposed to place something in the box for command line arguments? and if so what am I supposed to place there? Basiclly very other lesson has built fine for me until now, I have never needed to mess with this section before so I am not understanding what your asking me to do here.

Re: Having problems with this program building and am not getting errors

Posted 22 August 2011 - 10:42 PM

You're trying to use the variable you named "userInput" (which is traditionally named "args"). It's the only parameter for the Main method. This is where all command line arguments are stored in. So since you're trying to use it, you have to provide command line arguments.

Re: Having problems with this program building and am not getting errors

Posted 22 August 2011 - 11:01 PM

Try it and find out. But putting the name "userInput" won't do what you want. You put the actual input. Of course, if you're not planning on using command line parameters, and would rather prompt for input, you could do this with Console.ReadLine instead. I'm not sure if you're actually trying to use parameters or not.

Parameters means that you start the program with the parameters after the name. For instance:

ping -t google.com

Starts the program "ping" with parameters "-t" and "google.com". On the other hand, if you wanted to start the program and have it say "Please enter a number", you'd use Console.ReadLine after the prompt to capture user input.

Re: Having problems with this program building and am not getting errors

Posted 22 August 2011 - 11:14 PM

I understand from the link you showed me but what is it that I would need to do for my program everything I try does not seem to work, sorry this is the first time I have ever used command line parameters, and your help is appreciated;)