using the ' this. ' keyword. any small performance hit?

  • Thread starter Thread starter Matt Swift
  • Start date Start date
M

Matt Swift

If source contains lots of this. statements, does this incur any kind of
minor performance hit, I'd imagine it does as it's causing a check to be
performed?

Thanks
 
Matt Swift said:
If source contains lots of this. statements, does this incur any kind of
minor performance hit, I'd imagine it does as it's causing a check to be
performed?

No - any statement where you're implicitly using "this." is exactly the
same as the statement with it included explicitly.
 
Additionally ... why to depend on some one else..

Open up a console app..
write two method.. and do some updates to a variable using 'this' and
without using 'this'..

eg
private int i = 0;
private void checkthis()
{
this.i ++;
}

private void checknothis()
{
i++;
}

Compile this and check the IL... using ildasm.exe

You will see that both the IL are indentical which guranteed that there is
no performance cost at all...

In addition...

if (condition)
{
line
}

if (condition)
line

also don't have any difference..

Nirosh..
 
Ah,

Apologies. I was completely forgetting the way in which things are compiled
to IL first. They are of course going to be the same!

Thankyou all for your excellent answers in this, much appreciate. Do
forgive my stupidity!
 
Back
Top