Is there any point in ommitting arguments from main method definition?

  • Thread starter Thread starter garyusenet
  • Start date Start date
G

garyusenet

static void Main(string[] args)
{
}

If you know your programme will not take any string arguments, would it
make any difference at all if you removed the string arguments from the
code? And had this instead: -

static void Main()
{
}

I've checked and it compiles, but both versions compile as the same
size.

So i'm curious why they are both the same size.

Does the compiler check to see if the string arguments are actually
used in the main method body? And if they are not it removes them from
the method signature prior to compilation?

Thanks,

Gary.
 
static void Main(string[] args)
{
}

If you know your programme will not take any string arguments, would it
make any difference at all if you removed the string arguments from the
code? And had this instead: -

static void Main()
{
}

No, it wouldn't affect the execution of your program.
I've checked and it compiles, but both versions compile as the same
size.

So i'm curious why they are both the same size.

I didn't spend the time reading the specification so this is just
guess. I tried it myself and found that both executables are 16384
bytes which is 2^14. This leads me to believe that the compiler
allocates space for the executable in chunks. Since we're talking
about such a small change to the program it's not enough to change the
number of chunks needed.
Does the compiler check to see if the string arguments are actually
used in the main method body? And if they are not it removes them from
the method signature prior to compilation?

No, it doesn't. You can verify this by running ildasm on both
executables.
 
Thankyou very much Brian.

I hadn't encountered ildasm before it looks very useful.

Gary.

Brian said:
static void Main(string[] args)
{
}

If you know your programme will not take any string arguments, would it
make any difference at all if you removed the string arguments from the
code? And had this instead: -

static void Main()
{
}

No, it wouldn't affect the execution of your program.
I've checked and it compiles, but both versions compile as the same
size.

So i'm curious why they are both the same size.

I didn't spend the time reading the specification so this is just
guess. I tried it myself and found that both executables are 16384
bytes which is 2^14. This leads me to believe that the compiler
allocates space for the executable in chunks. Since we're talking
about such a small change to the program it's not enough to change the
number of chunks needed.
Does the compiler check to see if the string arguments are actually
used in the main method body? And if they are not it removes them from
the method signature prior to compilation?

No, it doesn't. You can verify this by running ildasm on both
executables.
 
Back
Top