performance issue (Tech Questions)

  • Thread starter Thread starter Champika Nirosh
  • Start date Start date
C

Champika Nirosh

Hi All,

I just wonder the differences between fallowings

if (myValue > 0)
{
DoThis();
}

&

if (myValue>0)
DoThis();

____________________________________
AND
____________________________________

If I call a variable with the "this" reference and if I call the same
variable without the "this" reference

i.e.

this.MyVariable

&

MyVariable

What are the advantages and disadvantages, if there are any...?
How it effect on the performance?

Thanks All

Nirosh.
 
Champika Nirosh said:
I just wonder the differences between fallowings

<snip>

One thing to do when considering this kind of thing is to test it -
either benchmark it, or at least look at the difference in IL. So,
here's a test program:

using System;

public class Test
{
int x=5;

void Foo()
{
if (x > 10)
DoSomething();
}

void Bar()
{
if (this.x > 10)
{
DoSomething();
}
}

void DoSomething()
{
}

static void Main()
{
}
}

Now looking at the IL for Foo and Bar using ildasm you can see that the
code generated is exactly the same - so there can't be any performance
differences.
 
In addition to what Jon said, I would add that the curly brackets are there
only to group stataments that belong to if and have no effect on generated
code.

Miha
 
Back
Top