Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Namespace consoleapplication1
{
Public class currency
{
Public uint dollars;
Public ushort cents;
Public currency ()
{
}
Public currency (uint dollars, ushort cents)
{
This. Dollars = dollars;
This. cents = cents;
}
Public override string tostring ()
{
Return string. Format ("{0: c}. {1,-2: 00}", dollars, cents );
}
Public static string getcurrencyuint ()
{
Return "RMB ";
}
Public static explicit operator currency (float value)
{
Checked
{
Uint dollars = (uint) value;
Ushort cents = (ushort) (value-dollars) * 100 );
Return new currency (dollars, cents );
}
}
Public Static Implicit operator float (currency value)
{
Return Value. dollars + value. cents/100366f;
}
Public Static Implicit operator currency (uint value)
{
Return new currency (value, 0 );
}
Public Static Implicit operator uint (currency value)
{
Return Value. dollars;
}
}
Delegate string getastring ();
Class Program
{
Static void main (string [] ARGs)
{
Int x = 40;
Getastring firststringmethod = x. tostring;
Console. writeline ("string is {0}", firststringmethod ());
Currency balance = new currency (34, 50 );
Firststringmethod = balance. tostring;
Console. writeline ("string is {0}", firststringmethod ());
Firststringmethod = new getastring (currency. getcurrencyuint );
Console. writeline ("string is {0}", firststringmethod ());
}
}
}
//
/// * The following is the running result. String is 40 string is ¥34.50 string is RMB. Press any key to continue ...*/