Click here to Skip to main content
15,896,111 members
Home / Discussions / C#
   

C#

 
AnswerRe: C# Project On Image Processing Pin
Pete O'Hanlon3-Jun-13 3:23
mvePete O'Hanlon3-Jun-13 3:23 
AnswerRe: C# Project On Image Processing Pin
Bishwajit Nepali3-Jun-13 6:12
Bishwajit Nepali3-Jun-13 6:12 
GeneralPracticing Passing Parameters Pin
N8tiv31-May-13 16:25
N8tiv31-May-13 16:25 
GeneralRe: Practicing Passing Parameters Pin
OriginalGriff31-May-13 21:15
mveOriginalGriff31-May-13 21:15 
GeneralRe: Practicing Passing Parameters Pin
N8tiv3-Jun-13 7:19
N8tiv3-Jun-13 7:19 
GeneralRe: Practicing Passing Parameters Pin
OriginalGriff3-Jun-13 7:59
mveOriginalGriff3-Jun-13 7:59 
GeneralRe: Practicing Passing Parameters Pin
Richard MacCutchan31-May-13 23:21
mveRichard MacCutchan31-May-13 23:21 
GeneralRe: Practicing Passing Parameters Pin
N8tiv3-Jun-13 1:02
N8tiv3-Jun-13 1:02 
Both you and the book lost me… You both are saying the same thing, but…

Here is the whole chapter, so you can see what they're talking about and maybe why I'm lost.

4-8 Using Program Arguments

One possible form of the Main method is:
static void Main(string[] args)

Using this form allows the C# program to accept as arguments a sequence
of strings. The arguments are received as string array elements named
args[0], args[1], and so forth. The string arguments can also be converted
to other data types, as explained in Chapter 3.

In the following example, the program receives two arguments at run
time. The program converts the first one to a long number and the second
to a double number, and then displays them and their product.

C#
Example 4-11
// Example 4-11.cs
// Parsing arguments
using System;
public class ParseClass
{
static void Main(string[] args)
{
long myLong = Convert.ToInt64(args[0]);
double myDouble = Convert.ToDouble(args[1]);
double result = myLong * myDouble;
Console.WriteLine("Your long number is: {0}", myLong);
Console.WriteLine("Your double number is: {0}", myDouble);
Console.WriteLine("The result of multiplication is: {0}",
result);
}
}


Sample Run:
Assuming that the program is called “example,” enter the following at the
command line:
> example 2 1.1

The output should be:

Your long number is: 2
Your double number is: 1.1
The result of multiplication is: 2.2

Drill 4-4
Rewrite the program created for Drill 4-2 to read the number and the
power as program arguments. For example, if the program is called
“power,” you can invoke it as shown in these sample runs:

Sample Run 1:
>power 4 2
The number 4 raised to the power 2 = 16
Sample Run 2:
>power 4 3
The number 4 raised to the power 3 = 64



Here is my code, it's basically the same as yours… Just the names of the variables are changed.
C#
using System;

namespace PracticePassingParameters
{
    class Program
    {
        static void Main(string[] args)
        {
            int FN = Convert.ToInt32(args[0]);
            int SN = Convert.ToInt32(args[1]);
            Console.Write(Math.Pow(FN, SN));
            Console.Read();
        }
    }
}


When I run it in the debugger, "index was outside the bounds of the array"… WTHConfused | :confused:

GeneralRe: Practicing Passing Parameters Pin
Richard MacCutchan3-Jun-13 1:20
mveRichard MacCutchan3-Jun-13 1:20 
GeneralRe: Practicing Passing Parameters Pin
N8tiv3-Jun-13 2:39
N8tiv3-Jun-13 2:39 
GeneralRe: Practicing Passing Parameters Pin
Richard MacCutchan3-Jun-13 6:15
mveRichard MacCutchan3-Jun-13 6:15 
GeneralRe: Practicing Passing Parameters Pin
N8tiv3-Jun-13 21:01
N8tiv3-Jun-13 21:01 
GeneralRe: Practicing Passing Parameters Pin
Richard MacCutchan3-Jun-13 21:15
mveRichard MacCutchan3-Jun-13 21:15 
GeneralRe: Practicing Passing Parameters Pin
N8tiv3-Jun-13 3:46
N8tiv3-Jun-13 3:46 
GeneralRe: Practicing Passing Parameters Pin
Richard MacCutchan3-Jun-13 6:11
mveRichard MacCutchan3-Jun-13 6:11 
QuestionTo detect all USB devices. Pin
ravi inder jeet singh31-May-13 15:44
ravi inder jeet singh31-May-13 15:44 
AnswerRe: To detect all USB devices. Pin
Dave Kreskowiak1-Jun-13 6:51
mveDave Kreskowiak1-Jun-13 6:51 
QuestionSkype in C# Pin
Kevin Marois31-May-13 12:12
professionalKevin Marois31-May-13 12:12 
AnswerRe: Skype in C# Pin
Ron Beyer31-May-13 12:14
professionalRon Beyer31-May-13 12:14 
GeneralRe: Skype in C# Pin
Kevin Marois31-May-13 12:15
professionalKevin Marois31-May-13 12:15 
GeneralRe: Skype in C# Pin
Ron Beyer31-May-13 12:22
professionalRon Beyer31-May-13 12:22 
GeneralRe: Skype in C# Pin
Kevin Marois31-May-13 12:28
professionalKevin Marois31-May-13 12:28 
QuestionGeneric and Inheritance issue Pin
Revolty31-May-13 11:27
Revolty31-May-13 11:27 
AnswerRe: Generic and Inheritance issue Pin
Ron Beyer31-May-13 12:02
professionalRon Beyer31-May-13 12:02 
GeneralRe: Generic and Inheritance issue Pin
Revolty31-May-13 12:52
Revolty31-May-13 12:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.