views:

69

answers:

2

With this method declaration (no overloads):

void Method(double d)
{
  // do something with d
}

Is there a (performance) difference at runtime between

void Main()
{
    Method(1);
    Method(1.0);
}

or does the compiler automatically convert the int literal to a double?

+7  A: 

The compiler will implicitly convert the int to a double.

There will be no penalty.

leppie
To add to this: You can always use Reflector to look at the resulting IL or what it looks like when converted back into C#.
Joey
+1  A: 

I just tried it. C# 3.0 generates the following IL for your first call:

ldc.r8 1.
call instance void ConsoleApplication1.Program::Method(float64)

So, no runtime conversion.

Maximilian Mayerl