Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

The compiler will implicitly convert the int to a double.

There will be no penalty.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top