What's wrong with args[0]

  • Thread starter Thread starter Curious
  • Start date Start date
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.
 
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.
 
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.
 
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!
 
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!
 
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.
 
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.
 
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.
 
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.
 
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!
 
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!
 
Back
Top