What's wrong with args[0]

C

Curious

Hi,

I have

static void Main(string[] args)
{
string dbConn = args[0]; // error here, "Index was
outside the bounds of the array."
}

However, when I run the debugger, it gives me an error about "Index
was outside the bounds of the array."

How shall I get this fixed? Thanks.
 
S

sloan

You need to check for nulls and lengths and such.

if(null!=args)
{
if(args.Length > 0) // or the .Count property is typical (not just
talking about this specific object)
{
string x = args[0];
}

}


Do Not write code that just blows up. Do some checking. Be proactive.



Are you passing in command line arguments? In the debugger, apparently you
are not.
 
S

sloan

You need to check for nulls and lengths and such.

if(null!=args)
{
if(args.Length > 0) // or the .Count property is typical (not just
talking about this specific object)
{
string x = args[0];
}

}


Do Not write code that just blows up. Do some checking. Be proactive.



Are you passing in command line arguments? In the debugger, apparently you
are not.
 
C

Curious

You need to check for nulls and lengths and such.

if(null!=args)
{
    if(args.Length > 0) // or the .Count property is typical (not just
talking about this specific object)
{
        string x = args[0];

}
}

Do Not write code that just blows up.  Do some checking.  Be proactive.

Are you passing in command line arguments?  In the debugger, apparentlyyou
are not.




       static void Main(string[] args)
       {
           string dbConn = args[0];  // error here, "Index was
outside the bounds of the array."
       }
However, when I run the debugger, it gives me an error about "Index
was outside the bounds of the array."
How shall I get this fixed? Thanks.- Hide quoted text -

- Show quoted text -

Thanks for the suggestion. It works!
 
C

Curious

You need to check for nulls and lengths and such.

if(null!=args)
{
    if(args.Length > 0) // or the .Count property is typical (not just
talking about this specific object)
{
        string x = args[0];

}
}

Do Not write code that just blows up.  Do some checking.  Be proactive.

Are you passing in command line arguments?  In the debugger, apparentlyyou
are not.




       static void Main(string[] args)
       {
           string dbConn = args[0];  // error here, "Index was
outside the bounds of the array."
       }
However, when I run the debugger, it gives me an error about "Index
was outside the bounds of the array."
How shall I get this fixed? Thanks.- Hide quoted text -

- Show quoted text -

Thanks for the suggestion. It works!
 
C

Curious

You need to check for nulls and lengths and such.

if(null!=args)
{
    if(args.Length > 0) // or the .Count property is typical (not just
talking about this specific object)
{
        string x = args[0];

}
}

Do Not write code that just blows up.  Do some checking.  Be proactive.

Are you passing in command line arguments?  In the debugger, apparentlyyou
are not.




       static void Main(string[] args)
       {
           string dbConn = args[0];  // error here, "Index was
outside the bounds of the array."
       }
However, when I run the debugger, it gives me an error about "Index
was outside the bounds of the array."
How shall I get this fixed? Thanks.- Hide quoted text -

- Show quoted text -

I need to pass arguments from a task/job, how shall I debug now? At
this point, I'm unable to create a task/job because I don't have that
permission yet. However, I want to know how I can debug.
 
C

Curious

You need to check for nulls and lengths and such.

if(null!=args)
{
    if(args.Length > 0) // or the .Count property is typical (not just
talking about this specific object)
{
        string x = args[0];

}
}

Do Not write code that just blows up.  Do some checking.  Be proactive.

Are you passing in command line arguments?  In the debugger, apparentlyyou
are not.




       static void Main(string[] args)
       {
           string dbConn = args[0];  // error here, "Index was
outside the bounds of the array."
       }
However, when I run the debugger, it gives me an error about "Index
was outside the bounds of the array."
How shall I get this fixed? Thanks.- Hide quoted text -

- Show quoted text -

I need to pass arguments from a task/job, how shall I debug now? At
this point, I'm unable to create a task/job because I don't have that
permission yet. However, I want to know how I can debug.
 
S

sloan

InVS2005:

Project Properties / Debug (Tab) / Start Options / Command Line Arguments


OR


string someVariable = "SomeDefaultValue";

if(null!=args)
{
if(args.Length > 0) // or the .Count property is typical (not just
talking about this specific object)
{
someVariable = args[0];
}

}





You need to check for nulls and lengths and such.

if(null!=args)
{
if(args.Length > 0) // or the .Count property is typical (not just
talking about this specific object)
{
string x = args[0];

}
}

Do Not write code that just blows up. Do some checking. Be proactive.

Are you passing in command line arguments? In the debugger, apparently you
are not.




static void Main(string[] args)
{
string dbConn = args[0]; // error here, "Index was
outside the bounds of the array."
}
However, when I run the debugger, it gives me an error about "Index
was outside the bounds of the array."
How shall I get this fixed? Thanks.- Hide quoted text -

- Show quoted text -

I need to pass arguments from a task/job, how shall I debug now? At
this point, I'm unable to create a task/job because I don't have that
permission yet. However, I want to know how I can debug.
 
S

sloan

InVS2005:

Project Properties / Debug (Tab) / Start Options / Command Line Arguments


OR


string someVariable = "SomeDefaultValue";

if(null!=args)
{
if(args.Length > 0) // or the .Count property is typical (not just
talking about this specific object)
{
someVariable = args[0];
}

}





You need to check for nulls and lengths and such.

if(null!=args)
{
if(args.Length > 0) // or the .Count property is typical (not just
talking about this specific object)
{
string x = args[0];

}
}

Do Not write code that just blows up. Do some checking. Be proactive.

Are you passing in command line arguments? In the debugger, apparently you
are not.




static void Main(string[] args)
{
string dbConn = args[0]; // error here, "Index was
outside the bounds of the array."
}
However, when I run the debugger, it gives me an error about "Index
was outside the bounds of the array."
How shall I get this fixed? Thanks.- Hide quoted text -

- Show quoted text -

I need to pass arguments from a task/job, how shall I debug now? At
this point, I'm unable to create a task/job because I don't have that
permission yet. However, I want to know how I can debug.
 
C

Curious

InVS2005:

Project Properties / Debug (Tab) / Start Options / Command Line Arguments

OR

string someVariable  = "SomeDefaultValue";

if(null!=args)
{
    if(args.Length > 0) // or the .Count property is typical (not just
talking about this specific object)
{
        someVariable = args[0];

}
}

Thanks for the advice. It works!
 
C

Curious

InVS2005:

Project Properties / Debug (Tab) / Start Options / Command Line Arguments

OR

string someVariable  = "SomeDefaultValue";

if(null!=args)
{
    if(args.Length > 0) // or the .Count property is typical (not just
talking about this specific object)
{
        someVariable = args[0];

}
}

Thanks for the advice. It works!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top