Click here to Skip to main content
15,901,284 members
Home / Discussions / C#
   

C#

 
GeneralRe: Need help with my very first c# application Pin
OriginalGriff7-Oct-10 9:21
mveOriginalGriff7-Oct-10 9:21 
GeneralRe: Need help with my very first c# application Pin
turbosupramk37-Oct-10 9:30
turbosupramk37-Oct-10 9:30 
GeneralRe: Need help with my very first c# application Pin
Luc Pattyn7-Oct-10 9:53
sitebuilderLuc Pattyn7-Oct-10 9:53 
GeneralRe: Need help with my very first c# application Pin
Charles Cox7-Oct-10 16:20
Charles Cox7-Oct-10 16:20 
GeneralRe: Need help with my very first c# application Pin
S Houghtelin7-Oct-10 9:34
professionalS Houghtelin7-Oct-10 9:34 
GeneralRe: Need help with my very first c# application Pin
Luc Pattyn7-Oct-10 9:55
sitebuilderLuc Pattyn7-Oct-10 9:55 
GeneralRe: Need help with my very first c# application Pin
S Houghtelin7-Oct-10 10:01
professionalS Houghtelin7-Oct-10 10:01 
GeneralRe: Need help with my very first c# application Pin
OriginalGriff7-Oct-10 9:20
mveOriginalGriff7-Oct-10 9:20 
So your first port of call is to find out just what args[0] is. Google can help: Google args[0] c#[^]
This second result explains it, and gives examples: MSDN on command line arguments[^]
This is your second (or first-and-a-half) port of call: MSDN. It knows everything (hah!) about C# and .NET
And it's free.
Impenetrable at times, but free. And very often worth tagging into a Google search: "args[0] c# MSDN" would give the article above as the first hit.

So, args[0] is the first command line argument to your console app. (or Winforms or whatever, but don't worry about that yet). This explains why it gave an ArgumentOutOfRange error when you tried to use it: you haven't supplied any command line arguments!

So, change your code to:
string host = "192.168.0.1";  // Default to my router
if (args.Count > 0)
   {
   host = args[0];
   }
And it would work with either a default value - my router - or the IP address you specify as a command line argument.
This means you can run your console app with:
myPing

(which would ping your router)
or
myPing 92.27.41.80

(which would ping me, for an hour or so until I turn the router off.)

Now do you see what I mean about it being important to work out why something isn't working, rather than just "fixing it"? Laugh | :laugh:
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

GeneralRe: Need help with my very first c# application Pin
turbosupramk37-Oct-10 10:01
turbosupramk37-Oct-10 10:01 
GeneralRe: Need help with my very first c# application Pin
turbosupramk37-Oct-10 10:12
turbosupramk37-Oct-10 10:12 
GeneralRe: Need help with my very first c# application Pin
OriginalGriff7-Oct-10 21:34
mveOriginalGriff7-Oct-10 21:34 
GeneralRe: Need help with my very first c# application Pin
turbosupramk38-Oct-10 4:28
turbosupramk38-Oct-10 4:28 
GeneralRe: Need help with my very first c# application Pin
OriginalGriff8-Oct-10 4:51
mveOriginalGriff8-Oct-10 4:51 
GeneralRe: Need help with my very first c# application Pin
turbosupramk313-Oct-10 7:20
turbosupramk313-Oct-10 7:20 
GeneralRe: Need help with my very first c# application Pin
S Houghtelin7-Oct-10 9:16
professionalS Houghtelin7-Oct-10 9:16 
AnswerRe: Need help with my very first c# application Pin
Nish Nishant7-Oct-10 8:17
sitebuilderNish Nishant7-Oct-10 8:17 
AnswerRe: Need help with my very first c# application Pin
MasttsaM13-Oct-10 22:43
MasttsaM13-Oct-10 22:43 
QuestionAbout creating Editable(fillable) PDF-forms Pin
sameermaske7-Oct-10 4:04
sameermaske7-Oct-10 4:04 
AnswerRe: About creating Editable(fillable) PDF-forms Pin
Ennis Ray Lynch, Jr.7-Oct-10 6:26
Ennis Ray Lynch, Jr.7-Oct-10 6:26 
QuestionParsing a text file. Pin
jenya77-Oct-10 3:21
jenya77-Oct-10 3:21 
AnswerMessage Closed Pin
7-Oct-10 3:41
stancrm7-Oct-10 3:41 
GeneralRe: Parsing a text file. Pin
jenya77-Oct-10 3:57
jenya77-Oct-10 3:57 
GeneralRe: Parsing a text file. Pin
#realJSOP7-Oct-10 23:41
professional#realJSOP7-Oct-10 23:41 
AnswerRe: Parsing a text file. Pin
PIEBALDconsult7-Oct-10 16:28
mvePIEBALDconsult7-Oct-10 16:28 
QuestionMicrosoft.Office.Interop.Excel BorderAround2 crash Pin
Blubbo7-Oct-10 2:58
Blubbo7-Oct-10 2:58 

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.