When overloading, what priority is the overload called? #6924
Answered
by
CyrusNajmabadi
zms9110750
asked this question in
Q&A
-
I have a class to help me customize the format to numbers public struct Float : IFormattable
{
float value;
public override string ToString() => ToString(null, null);
public string ToString(string format, IFormatProvider formatProvider)...
public static implicit operator Float(float f)
{
return new Float { value = f };
}
public static implicit operator float(Float f)
{
return f.value;
}
} Why doesn't he think that my parameter is of type object, but he implicitly converts it to float, and then uses float overloading? Float f = 12345678;
Console.WriteLine(f.ToString()); //12.3M
Console.WriteLine(f); //123456789
Console.WriteLine($"{f}"); //12.3M |
Beta Was this translation helpful? Give feedback.
Answered by
CyrusNajmabadi
Jan 28, 2023
Replies: 1 comment 1 reply
-
Overload resolution is specified here: https://github.com/dotnet/csharpstandard/blob/standard-v6/standard/expressions.md#1164-overload-resolution |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
zms9110750
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Overload resolution is specified here: https://github.com/dotnet/csharpstandard/blob/standard-v6/standard/expressions.md#1164-overload-resolution