static void Main(string stringarg, int intarg)
{
foreach(string arg in stringarg);
Console.WriteLine(arg);
Console.WriteLine(intarg);
Console.ReadKey();
}
The compiler doesn’t throw an exception for the missing braces round the foreach condition, so if i remove the int intarg from the code and the line Console.WriteLine(intarg); the app runs ok and outputs the arg strings. If I reinput the integer argument in Main(string stringarg, int intarg) I get the error…“…<project.function>has the wrong signature to be an entry point” or "<project.function>"does not contain a static ‘main’ method suitable for an entry point…
Thank you for your explanation walbalooshi. You’ve confirmed what I thought - that the declaration was illegal, and given me a solution to the problem. However I am still baffled by the exercise instruction in the book I am learning from…
“Write an application that uses two command-line arguments to place values into a string and an integer variable, respectively. Then display these values.”
This seems to suggest that two separate arguments can be passed rather than isolating and converting part of a string array to int, or performing any parsing as per your suggestion. Do you think the instruction is misleading or perhaps it makes more sense to you than it does to me?
I believe they are talking about the arguments that you send the program through the command line when you run the program. Ex:
MyApplication.exe string 4
Now the string args parameter will contain two items
args[0] = “string”
args[1] = “4”
Now you can put the values in the args array into variables remembering that you need to parse the args[1] content to an Int with the function I showed above, then display the contents of the variables using the Console.Write or .WriteLine methods
Yes, not using braces in C# is perfectly legal, but I would strongly suggest using them and it just keeps things clean when you have a lot of code as it is a lot easier to see exactly whats in the if or loop.
Anywayz… enough about that. command line args are usually all string, so I would assume they want you to know that you need to convert it to int, but, at the same time, ur writing it out without doing anything with it, so no actual need to convert to int, but it is the basics that you will need to know later for when you actually want to work with the int