C# Methods Differing By Return Type Only
Wednesday 15 January 2003
While doing some prototyping on how to handle optional struct members in XML-RPC.NET I realized that it is possible to define methods in C# which differ only by return type. This is a feature of the CLR which most languages don't support and C# is the same...except for the definition of operator conversion methods. For example:
class MyInteger
{
....
public static implicit operator Int32(MyInteger mi)
{
return mi.ToInt32;
}
public static implicit operator Single(MyInteger mi)
{
return mi.ToSingle();
}
....
}
In the resulting IL these two methods have the following signatures:
public static int32 op_Implicit(class XmlRpcInt mi) public static float32 op_Implicit(class XmlRpcInt mi)
Posted by
at 08:55 AM.
Permalink.
Copyright © Charles Cook.
Valid XHTML 1.0