Forum Xamarin Xamarin.iOS

setting the default value to a nfloat optional parameter fails to compile

softlionsoftlion FRBeta ✭✭✭

Hi, i'm creating a method with a default parameter value likes this:

    public void MyMethod(nfloat width=0) { }

This fails to compile with error: "A value of type int can not be used as a default parameter because there are no standard conversions to type nfloat".

The xamarin doc says int, uint and float are all implicitly convertible to nint, nuint and nfloat as 32 bits will always fit in 32 or 64 bits.

What is wrong with my code ?



  • RolfBjarneKvingeRolfBjarneKvinge USXamarin Team Xamurai

    You can't have optional nfloat parameters.

    nfloat is not an intrinsic type, and thus it's not possible (it's the same reason you can't declare nfloat constants).

  • GeoffArmstrongGeoffArmstrong CAMember ✭✭

    You can say nfloat width = default(nfloat) which works out to saying nfloat width = 0.

    But you can't really do any other optional nfloat parameters.

  • tofutimtofutim USUniversity ✭✭

    So there is no way to function myfunc(nint value = -1)? Only zero is possible?

Sign In or Register to comment.