vendredi 9 janvier 2015

Ambiguous extension method call between float and double


Vote count:

1




I have following extension methods, one for float and one for double.



public static string ToTimeString(this float f, TimeStringAccuracy accuracyFlags = DefaultAccuracyFlags, TimeStringSeparator separator = DefaultSeparator)


public static string ToTimeString(this double d, TimeStringAccuracy accuracyFlags = DefaultAccuracyFlags, TimeStringSeparator separator = DefaultSeparator)


When i call the functions from Visual Studio unit tests the tests run correctly and the call is not ambiguous. When i call the functions from Unity3D code for float (using Mono) the call is ambiguous between these two. Why doesn't the compiler know that it should be calling the float extension? Might it be Mono causing this?


This is the call:



float i = 1f;
i.ToTimeString();


Compiler error:



Assets/Scipts/UIScripts/GameplayUIWindow.cs(61,48): error CS0121: The call is ambiguous between the following methods or properties: ToTimeString(this double, TimeStringAccuracy, TimeStringSeparator)' and `ToTimeString(this float, TimeStringAccuracy, TimeStringSeparator)'


asked 1 min ago







Ambiguous extension method call between float and double

Aucun commentaire:

Enregistrer un commentaire